Kill processes which take up too much cpu usage after certain time of running.
Hello,
I'm running an Ubuntu server with Apache and every once in a while I get processes that hang at CLOSE_WAIT. The only solution I've found is to just kill the process. Instead of doing this manually is there a way to kill the processes that hang automatically, with like pkill or something. Something that looks for a process that has taken up more than lets say 75% of the cpu for at least 1 minute or so. Thanks in advance. |
You should be able to do that w/ cron and a script ....
|
Any idea on how I can go about doing this?
I was looking through /proc/PID/stat to see if I can calculate the cpu usage and execution time. |
Pseudo-code following...
Something like: Code:
for i in $(netstat -tpn|awk -F/ '/apache/ && /CLOSE_WAIT/{print $1}) |
Thanks that helped a lot! :)
I modified it a bit and got this: Code:
ps --user www-data -o pid,time,pcpu|awk '{ |
Maybe you should change your test to match the data ?. Remembering it's a string of course ...
|
Quote:
Does this help? Code:
$ echo a b 00:12:34 | awk '{split($3,a, ":");print a[1]*60*60+ a[2]*60 + a[3]}' |
Personally, I wouldn't bother splitting it - just test as-is.
|
All times are GMT -5. The time now is 03:39 PM. |