LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This 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



Reply
 
Search this Thread
Old 07-13-2012, 11:55 PM   #1
ytyyutianyun
Member
 
Registered: Nov 2011
Posts: 48

Rep: Reputation: Disabled
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
 
Old 07-13-2012, 11:58 PM   #2
keepitfunky4
LQ Newbie
 
Registered: Jul 2012
Distribution: Ubuntu 10.04
Posts: 4

Rep: Reputation: Disabled
sudo kill 30534
 
Old 07-14-2012, 12:11 AM   #3
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 12,497

Rep: Reputation: 1077Reputation: 1077Reputation: 1077Reputation: 1077Reputation: 1077Reputation: 1077Reputation: 1077Reputation: 1077
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-14-2012 at 12:42 AM. Reason: added cpu% in output list
 
Old 07-14-2012, 12:27 AM   #4
keepitfunky4
LQ Newbie
 
Registered: Jul 2012
Distribution: Ubuntu 10.04
Posts: 4

Rep: Reputation: Disabled
I apologize I thought you wanted to delete by pid
 
Old 07-14-2012, 02:35 AM   #5
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 12,497

Rep: Reputation: 1077Reputation: 1077Reputation: 1077Reputation: 1077Reputation: 1077Reputation: 1077Reputation: 1077Reputation: 1077
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".
 
Old 07-14-2012, 08:57 PM   #6
ytyyutianyun
Member
 
Registered: Nov 2011
Posts: 48

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by syg00 View Post
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
 
Old 07-14-2012, 10:49 PM   #7
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 12,497

Rep: Reputation: 1077Reputation: 1077Reputation: 1077Reputation: 1077Reputation: 1077Reputation: 1077Reputation: 1077Reputation: 1077
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 ""}'
 
Old 07-15-2012, 01:44 AM   #8
tarunchawla
Member
 
Registered: Mar 2010
Location: New Delhi,India
Distribution: Ubuntu 14.04
Posts: 115

Rep: Reputation: 3
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.
 
Old 07-15-2012, 10:16 PM   #9
ytyyutianyun
Member
 
Registered: Nov 2011
Posts: 48

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by syg00 View Post
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.
 
  


Reply

Tags
add, cpu


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
how to find all processes cpu utilization & the cpu processor in linux? vasanth.v999 Linux - Server 7 01-10-2012 09:43 AM
[SOLVED] processes and CPU 4-core xeon123 Linux - General 1 03-26-2011 01:53 PM
script to delete some processes Carlos2dub Programming 1 12-14-2007 10:18 AM
Processes running in each CPU senlleiro Linux - General 3 10-18-2006 07:59 PM
two processes on different CPU's CobraMagic Linux - General 1 11-08-2002 12:34 PM


All times are GMT -5. The time now is 09:18 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration