find and kill process through lsof marked as deleted
Hi can any one help me to write a script, to find and kill process that own a file marked as deleted in lsof and file size is greater than 2GB
Thanks and Regards |
Quote:
|
Hi Turbocapitalist, thanks for the update, and we came up with below
lsof -a +L1 | awk -F" " '$8 > 1073741824 {print $2}' | sed 's\^\kill -9 \' > /tmp/kill_script then we run /tmp/kill_script Thanks and Regards |
Nice. Are you sure that column 8 is the size? On Ubuntu, I have column 7 as the size. Also you can skip the extra step of making a file with "xargs"
Code:
lsof -a +L1 | awk '$7 > 1073741824 && NR >1 {print $2}' | sort -nu | xargs kill |
Depending on the process "kill -9" will not allow it to gracefully exit. If other files are open it will lose buffers you just might want to keep. Use -3 instead.
If the process maintains its own log and the process must be restarted, you might try -1 instead. For many daemon services this is a signal to close logs and reopen them, and without losing any active connections. This is how a log rotate procedure works. |
Thanks Jpollard!
Thanks all and Best Regards |
All times are GMT -5. The time now is 11:50 PM. |