[SOLVED] How to delete the application processes by CPU
Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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
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.
Last edited by syg00; 07-13-2012 at 11:42 PM.
Reason: added cpu% in output list
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".
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".
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
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.
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]}'
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.