How to delete the application processes by CPU
Landing node can't Perform any program because people weren't able to log on as normal if too many program ran on it. I have warned those people, But they don't listen.
I used to delete these program one by one.Then how to delete the application processes by "%CPU" For example USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND 680 30534 71.0 0.6 93888 49156 ? S Jul10 4146:06 /public/Fluent root 5692 0.0 0.0 5652 792 ? S May04 0:04 top root 7319 0.0 0.1 114692 16032 ? Sl Jul03 0:00 gnome-terminal root 7325 0.0 0.0 5744 608 ? S Jul03 0:00 gnome-pty-helpe delete the "680" because of 71.0 Thanks |
sudo kill 30534
|
Better perhaps to use "ps" rather than "top". It has options to get rid of the header, sort by CPU% and only display (for example) the pids and cpu%. Then simply run those through a loop to kill those above a certain usage.
|
I apologize I thought you wanted to delete by pid
|
Just had another thought - if you need instantaneous cpu% you'll really need "top". But you'll have to toss the header away yourself. "awk" handles all the required as a "one-liner".
|
Quote:
Code:
kill -9 `ps -ef|grep top|grep -v grep|awk '{print $2}'` |
You probably don't have top running when you run the script.
Certainly isn't the way I'd do it - see post #3, and read the ps manpage for how to do what I suggested. Then pipe it to awk to check the cpu% - you can do the kill command in awk using "system". That way you can easily loop through the whole list automatically. Something like this should do it Code:
awk '($2 > 70) {system("kill -9 "$1) ; print ""}' |
just write "top" in terminal(if u don't have root privileges then use "sudo top"). It will list the processes with pid,then write "k" which is used to kill,then it will ask pid and then write the pid which will shown along with name of process and press enter.
|
Quote:
1. Code:
ps aux|awk 'NR!=1{a[$1]+=$3}END{for(i in a)print i" CPU IS "a[i]}' 2. Code:
ps aux|awk '($3 > 70) {system("kill -9 "$2) ; print ""}' |
All times are GMT -5. The time now is 02:10 AM. |