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 04-19-2013, 08:37 AM   #1
linuxkid12
LQ Newbie
 
Registered: Apr 2013
Posts: 6

Rep: Reputation: Disabled
Script to list processes taking more than 10% of CPU time


Hi,
I'm trying to write a script that lists all processes taking more than 10% of CPU time. I have no idea where to start other than ps aux lists all processes. How do i sort it so that it only lists those over 10%?
 
Old 04-19-2013, 08:46 AM   #2
cliffordw
Member
 
Registered: Jan 2012
Location: South Africa
Posts: 250

Rep: Reputation: 107Reputation: 107
ps aux|awk '{if ($3 > 10) {print;}}'
 
1 members found this post helpful.
Old 04-19-2013, 08:52 AM   #3
linuxkid12
LQ Newbie
 
Registered: Apr 2013
Posts: 6

Original Poster
Rep: Reputation: Disabled
So if i want to put the results in a text file i do:

ps aux | awk '{$3 > 10}' > example.txt

Or do i need more??
 
Old 04-19-2013, 08:58 AM   #4
millgates
Member
 
Registered: Feb 2009
Location: 192.168.x.x
Distribution: Slackware
Posts: 651

Rep: Reputation: 269Reputation: 269Reputation: 269
it's either
Code:
ps aux | awk '{if($3 > 10) print}' > example.txt
or

Code:
ps aux | awk '$3 > 10 {print}' > example.txt
or, using the fact that the default action in awk is print, even

Code:
ps aux | awk '$3 > 10' > example.txt
 
1 members found this post helpful.
Old 04-19-2013, 09:39 AM   #5
linuxkid12
LQ Newbie
 
Registered: Apr 2013
Posts: 6

Original Poster
Rep: Reputation: Disabled
thanks, how would i lower the priority of processes over 10%? renice?
 
Old 04-19-2013, 09:56 AM   #6
shivaa
Senior Member
 
Registered: Jul 2012
Location: Grenoble, Fr.
Distribution: Sun Solaris, RHEL, Ubuntu, Debian 6.0
Posts: 1,797
Blog Entries: 4

Rep: Reputation: 285Reputation: 285Reputation: 285
Memory consumption keep changing for processes. At some instance that could be more than 10% but on next moment that could be less than 10%.

Second thing, you can check memory consumption by variaous processs using top cmd, and that need to be stopped using key like q. So it's not easy to put the top command in script and capture it output in respect of memory consumption. Also did you realise, how many times or how your script will execute to check mem. consumption by various processes?

However, I would suggest you to use top command only whenever you need to check high mem. consuming processes.

On the other hand if you want to check using ps, then try this:
Code:
ps -eo pmem,pcpu,pid | sort -nr -k2

Last edited by shivaa; 04-19-2013 at 09:59 AM.
 
Old 04-21-2013, 01:09 PM   #7
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Debian sid + kde 3.5 & 4.4
Posts: 6,823

Rep: Reputation: 1946Reputation: 1946Reputation: 1946Reputation: 1946Reputation: 1946Reputation: 1946Reputation: 1946Reputation: 1946Reputation: 1946Reputation: 1946Reputation: 1946
No need to use sort, which may end up putting the header line in the wrong place. ps can do that for you too:

Code:
ps -eo pmem,pcpu,pid k -pcpu
 
1 members found this post helpful.
Old 04-21-2013, 07:06 PM   #8
unSpawn
Moderator
 
Registered: May 2001
Posts: 26,944
Blog Entries: 54

Rep: Reputation: 2731Reputation: 2731Reputation: 2731Reputation: 2731Reputation: 2731Reputation: 2731Reputation: 2731Reputation: 2731Reputation: 2731Reputation: 2731Reputation: 2731
Quote:
Originally Posted by David the H. View Post
No need to use sort, which may end up putting the header line in the wrong place.
Why would you want a header if you're not using it?
Code:
ps --noheaders -eo pmem,pcpu,pid k -pcpu
 
Old 04-23-2013, 08:53 AM   #9
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Debian sid + kde 3.5 & 4.4
Posts: 6,823

Rep: Reputation: 1946Reputation: 1946Reputation: 1946Reputation: 1946Reputation: 1946Reputation: 1946Reputation: 1946Reputation: 1946Reputation: 1946Reputation: 1946Reputation: 1946
I didn't think to add that when I posted, but I did think of it later. So it was going to go into my next comment, if nobody brought it up.
 
Old 04-23-2013, 02:37 PM   #10
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 1,978

Rep: Reputation: 512Reputation: 512Reputation: 512Reputation: 512Reputation: 512Reputation: 512
Also, if your system is using cgroups for interactive scheduling, renice doesn't really work.

What happens is that the cgroup does global scheduling, the nice values then schedule within a single cgroup. So changing the nice value will only affect the scheduling of the processes within that single cgroup, and if the other processes are I/O bound, the reniced process will still get the same CPU attention.

It doesn't matter if what you are trying to do is give a specific process more time by reducing the priority of other processes (those not in the same cgroup as the desired process). Even increasing the scheduling priority of a specific process has no effect.
 
  


Reply


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
X taking up a lot CPU time kurnia1 Linux - Server 2 04-13-2008 08:23 PM
many instances of smbd taking up much cpu time kaplan71 Linux - Server 1 05-10-2007 12:54 PM
X Server taking CPU processes pradi_net Linux - Software 5 08-20-2004 01:58 AM
how do i find which script is taking up my cpu time? Pete Dogg Linux - Software 4 07-23-2004 06:35 PM
magicdev taking up too much cpu time phahn Linux - Software 2 04-29-2002 01:13 PM


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

Main Menu
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