LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
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-13-2010, 09:17 AM   #1
dave12
LQ Newbie
 
Registered: Apr 2010
Posts: 7

Rep: Reputation: 0
listing cpu usage with top command


Hi,

Im trying to list the cpu usage of all process that have a cpu usage of 10% or more. Im not interested in the lower usages. Im using the top command and can get a list of all the cpu usage for all the process but cant only get the processes with 10% or more.

Ideally I'd want these processes sent to a new file. Would I be able to cat the cpu usages and PID into a file?

Any Ideas?

Thanks
 
Old 04-13-2010, 09:22 AM   #2
PMP
Member
 
Registered: Apr 2009
Location: ~
Distribution: RHEL, Fedora
Posts: 381

Rep: Reputation: 58
man ps, look for %cpu
 
Old 04-16-2010, 07:36 AM   #3
dave12
LQ Newbie
 
Registered: Apr 2010
Posts: 7

Original Poster
Rep: Reputation: 0
Cheers, i've looked at the ps and got a script that can put the pcpu in a variable. When i try to use an if statement to make only processes taking 10% or over of cpu time i get an error.

Heres the script

#!/bin/sh

PS_RESULTS=`ps -eo pcpu`

if [ $PS_RESULTS -ge 10 ]; then

echo $PS_RESULTS

fi

i get the error:
[: 9: 0.0: unexpected operator

any ideas?

cheers
 
Old 04-16-2010, 07:53 AM   #4
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 14,839

Rep: Reputation: 1822Reputation: 1822Reputation: 1822Reputation: 1822Reputation: 1822Reputation: 1822Reputation: 1822Reputation: 1822Reputation: 1822Reputation: 1822Reputation: 1822
I would suggest you do the echo first - you might be surprised what you are trying to compare against.
 
Old 04-16-2010, 07:59 AM   #5
dave12
LQ Newbie
 
Registered: Apr 2010
Posts: 7

Original Poster
Rep: Reputation: 0
Thanks for the reply.

I think I see my problem, I'm printing out the whole %CPU column, not just the values. How would I get around this?

Cheers
 
Old 04-16-2010, 08:03 AM   #6
cola
Senior Member
 
Registered: Sep 2007
Location: Dhaka,Bangladesh
Distribution: Debian
Posts: 1,031

Rep: Reputation: 63
Quote:
Originally Posted by dave12 View Post
Thanks for the reply.

I think I see my problem, I'm printing out the whole %CPU column, not just the values. How would I get around this?

Cheers
Mark the thread as "[SOLVED]" if it's solved.
 
0 members found this post helpful.
Old 04-16-2010, 08:07 AM   #7
PMP
Member
 
Registered: Apr 2009
Location: ~
Distribution: RHEL, Fedora
Posts: 381

Rep: Reputation: 58
Code:
ps -eo pcpu --sort=%cpu | awk '($0 > 10) {print}'
 
Old 04-16-2010, 08:10 AM   #8
dave12
LQ Newbie
 
Registered: Apr 2010
Posts: 7

Original Poster
Rep: Reputation: 0
Ah i see,

Thanks a lot for the help. Solved!
 
Old 04-16-2010, 08:13 AM   #9
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 14,839

Rep: Reputation: 1822Reputation: 1822Reputation: 1822Reputation: 1822Reputation: 1822Reputation: 1822Reputation: 1822Reputation: 1822Reputation: 1822Reputation: 1822Reputation: 1822
Personally, I always find it useful to include the process (or at least command) that's using that CPU.
 
  


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
CPU usage from top jr8rdt Linux - Newbie 10 08-17-2011 07:46 AM
Other than top command which cmd is used to find the cpu usage and disk space sathish80 Linux - Newbie 2 11-15-2006 01:43 AM
Top CPU usage explanation penguinco Fedora 3 11-30-2004 02:01 PM
need top clone- to measure CPU usage pao Linux - Software 4 10-07-2004 10:46 AM
Individual CPU usage not showing in ps/top hulli Linux - General 2 08-24-2004 03:44 AM


All times are GMT -5. The time now is 10:34 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration