LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   How to delete the application processes by CPU (https://www.linuxquestions.org/questions/linux-newbie-8/how-to-delete-the-application-processes-by-cpu-4175416624/)

ytyyutianyun 07-13-2012 10:55 PM

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

keepitfunky4 07-13-2012 10:58 PM

sudo kill 30534

syg00 07-13-2012 11:11 PM

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.

keepitfunky4 07-13-2012 11:27 PM

I apologize I thought you wanted to delete by pid

syg00 07-14-2012 01:35 AM

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".

ytyyutianyun 07-14-2012 07:57 PM

Quote:

Originally Posted by syg00 (Post 4727701)
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".

Is this right
Code:

kill -9 `ps -ef|grep top|grep -v grep|awk '{print $2}'`
But nothing happen? why and thanks

syg00 07-14-2012 09:49 PM

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 ""}'

tarunchawla 07-15-2012 12:44 AM

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.

ytyyutianyun 07-15-2012 09:16 PM

Quote:

Originally Posted by syg00 (Post 4728353)
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 ""}'

Thanks,you are great. I use your way

1.
Code:

ps aux|awk 'NR!=1{a[$1]+=$3}END{for(i in a)print i" CPU IS "a[i]}'
To see what is awesome

2.
Code:

ps aux|awk '($3 > 70) {system("kill -9 "$2) ; print ""}'
Thanks for helping ,Thanks for all of you.


All times are GMT -5. The time now is 02:10 AM.