View Single Post
  #1  
Old 11th March 2006, 23:44
edge edge is offline
Moderator
 
Join Date: Dec 2005
Location: The Netherlands
Posts: 2,036
Thanks: 268
Thanked 152 Times in 132 Posts
Default req: Bash / Script to auto kill PID if it's needed....

Hello nice people from HowtoForge :-)

I'm really in need of a script (bash will do) to kill a PID/USER when it's taking 99% of %CPU power for over a set time!

I was looking of a way of doing this with some use of top

When running top like this: top -1 -n 1 -b -u coldfusion it will show only the Coldfusion PID/USER once.
The PID/USER that is taking 99% of cpu power will also sit at the top of the list.

Quote:
top -1 -n 1 -b -u coldfusion
top - 23:35:47 up 1 day, 1:37, 2 users, load average: 2.74, 2.22, 2.24
Tasks: 243 total, 5 running, 238 sleeping, 0 stopped, 0 zombie
Cpu0 : 17.6% us, 11.3% sy, 0.0% ni, 71.1% id, 0.0% wa, 0.0% hi, 0.0% si
Cpu1 : 20.0% us, 11.4% sy, 0.0% ni, 68.6% id, 0.0% wa, 0.0% hi, 0.0% si
Cpu2 : 20.3% us, 9.0% sy, 0.0% ni, 70.5% id, 0.2% wa, 0.0% hi, 0.0% si
Cpu3 : 19.4% us, 9.0% sy, 0.0% ni, 70.8% id, 0.4% wa, 0.0% hi, 0.3% si
Mem: 2068288k total, 1868620k used, 199668k free, 120004k buffers
Swap: 787176k total, 52k used, 787124k free, 1034136k cached

PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
2934 coldfusi 18 0 21812 6396 3300 R 99.4 0.3 0:00.11 convert
8351 coldfusi 16 0 880m 506m 26m R 48.7 25.1 26:09.50 cfmx7
30206 coldfusi 16 0 880m 506m 26m S 17.5 25.1 0:04.90 cfmx7
26654 coldfusi 15 0 880m 506m 26m S 9.7 25.1 15:55.54 cfmx7
31087 coldfusi 15 0 880m 506m 26m S 9.7 25.1 9:37.35 cfmx7
(as you can see, the PID 2934 (user coldfusi) is taking with the command convert over 99% of CPU pwrd)

What I'm after is some script (bash?) that I can run on a cron job every 5 / 10 minutes to see if coldfusi with the command convert is sitting at or over 99%, and if so to auto kill the PID!

Anyone here who can help/show me how to make this?

Thank you...

Noel
Reply With Quote
Sponsored Links