LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 09-06-2010, 10:32 AM   #1
ahmedb72
Member
 
Registered: Jan 2006
Location: Sydney
Distribution: RHEL
Posts: 72

Rep: Reputation: 15
process cpu usage


Hi all,

If I, using sar or vmstat, found that there is a CPU load on my Linux box. How can I know the top processes consuming the CPU?

Thanks in advance.

RHEL 5.2
 
Old 09-06-2010, 11:04 AM   #2
AlucardZero
Senior Member
 
Registered: May 2006
Location: USA
Distribution: Debian
Posts: 4,824

Rep: Reputation: 615Reputation: 615Reputation: 615Reputation: 615Reputation: 615Reputation: 615
"ps" or "top" ?
 
Old 09-06-2010, 11:10 AM   #3
ahmedb72
Member
 
Registered: Jan 2006
Location: Sydney
Distribution: RHEL
Posts: 72

Original Poster
Rep: Reputation: 15
top is an interactive command. I need a command line statement.

Regarding ps, what are the options to display most CPU demanding processes?
 
Old 09-06-2010, 11:27 AM   #4
djsmiley2k
Member
 
Registered: Feb 2005
Location: Coventry, UK
Distribution: Home: Gentoo x86/amd64, Debian ppc. Work: Ubuntu, SuSe, CentOS
Posts: 343
Blog Entries: 1

Rep: Reputation: 72
Google says...

Quote:
Originally Posted by The interwebs
k spec specify sorting order. Sorting syntax is
[+|-]key[,[+|-]key[,...]] Choose a multi-letter key from the
STANDARD FORMAT SPECIFIERS section. The "+" is optional since
default direction is increasing numerical or lexicographic
order. Identical to --sort. Examples:
ps jaxkuid,-ppid,+pid
ps axk comm o comm,args
ps kstart_time -ef
As for working out what k is, I'll leave that as an exercise for the reader

Quote:
hint: google ps man page
 
Old 09-06-2010, 12:06 PM   #5
smoker
Senior Member
 
Registered: Oct 2004
Distribution: Fedora Core 4, 12, 13, 14, 15, 17
Posts: 2,279

Rep: Reputation: 250Reputation: 250Reputation: 250
Quote:
Originally Posted by ahmedb72 View Post
top is an interactive command.
Not strictly true.

try running

Code:
top -n 1
 
Old 09-06-2010, 12:55 PM   #6
AlucardZero
Senior Member
 
Registered: May 2006
Location: USA
Distribution: Debian
Posts: 4,824

Rep: Reputation: 615Reputation: 615Reputation: 615Reputation: 615Reputation: 615Reputation: 615
Are you asking for a historical list?
 
Old 09-06-2010, 01:08 PM   #7
ahmedb72
Member
 
Registered: Jan 2006
Location: Sydney
Distribution: RHEL
Posts: 72

Original Poster
Rep: Reputation: 15
Hi Smoker,

"top -n 1" gives me output similar to what I want. But I'm suspicious about what it displays though. Because I'm running dozens of client processes which all consume CPU. ps command displays those processes, but the top command displays only a fraction of them.

Code:
[root@srv100] top -n 1
top - 04:04:04 up  3:05,  3 users,  load average: 87.93, 52.05, 21.98
Tasks: 304 total,  89 running, 215 sleeping,   0 stopped,   0 zombie
Cpu(s): 11.3%us,  0.6%sy,  0.0%ni, 87.5%id,  0.5%wa,  0.0%hi,  0.0%si,  0.0%st
Mem:   2075608k total,  1113028k used,   962580k free,    77180k buffers
Swap:  4194296k total,   443820k used,  3750476k free,   426336k cached

  PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND
24855 oracle    25   0 1164m  22m  21m R   20  1.1   0:06.79 oracle
24857 oracle    25   0 1164m  22m  20m R   20  1.1   0:08.99 oracle
24897 oracle    25   0 1164m  22m  20m R   20  1.1   0:07.30 oracle
24905 oracle    25   0 1164m  22m  20m R   20  1.1   0:07.09 oracle
25028 oracle    25   0 1164m  23m  21m R   20  1.1   0:05.69 oracle
25073 oracle    25   0 1164m  22m  21m R   20  1.1   0:07.10 oracle
25077 oracle    25   0 1164m  23m  21m R   20  1.1   0:06.09 oracle
25085 oracle    25   0 1164m  23m  21m R   20  1.1   0:05.49 oracle
24774 oracle    25   0 1164m  22m  20m R   12  1.1   0:09.15 oracle
25026 oracle    25   0 1164m  22m  21m R   12  1.1   0:07.15 oracle
24901 oracle    25   0 1164m  23m  21m R   10  1.1   0:06.69 oracle
25079 oracle    25   0 1164m  23m  21m R   10  1.2   0:05.39 oracle
    1 root      15   0  2060  624  532 S    0  0.0   0:01.86 init
    2 root      RT  -5     0    0    0 S    0  0.0   0:00.34 migration/0
    3 root      34  19     0    0    0 R    0  0.0   0:00.00 ksoftirqd/0
    4 root      RT  -5     0    0    0 S    0  0.0   0:00.00 watchdog/0
    5 root      RT  -5     0    0    0 S    0  0.0   0:00.55 migration/1
    6 root      37  19     0    0    0 R    0  0.0   0:00.00 ksoftirqd/1
    7 root      RT  -5     0    0    0 S    0  0.0   0:00.00 watchdog/1
    8 root      10  -5     0    0    0 S    0  0.0   0:00.00 events/0
    9 root      10  -5     0    0    0 S    0  0.0   0:00.00 events/1
   10 root      10  -5     0    0    0 S    0  0.0   0:00.00 khelper
   11 root      11  -5     0    0    0 S    0  0.0   0:00.00 kthread
   15 root      10  -5     0    0    0 S    0  0.0   0:00.54 kblockd/0
   16 root      10  -5     0    0    0 S    0  0.0   0:00.10 kblockd/1
   17 root      15  -5     0    0    0 S    0  0.0   0:00.00 kacpid
  178 root      13  -5     0    0    0 S    0  0.0   0:00.00 cqueue/0
  179 root      13  -5     0    0    0 S    0  0.0   0:00.00 cqueue/1
  182 root      13  -5     0    0    0 S    0  0.0   0:00.00 khubd
  184 root      10  -5     0    0    0 S    0  0.0   0:00.00 kseriod

# see here number of commands
[root@srv100] ps -ef | grep oracle | wc -l
202
 
Old 09-06-2010, 06:05 PM   #8
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 21,128

Rep: Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120
You were advised to read the manpage(s) - had you done so, you would know:
- "ps" can be (even reverse) sorted on any column
- "top" can show threads individually, or accumulated.

Personally I find "ps" more useful for this kind of thing, as it can be setup to not require any post-processing.
 
Old 09-07-2010, 06:52 AM   #9
ahmedb72
Member
 
Registered: Jan 2006
Location: Sydney
Distribution: RHEL
Posts: 72

Original Poster
Rep: Reputation: 15
My question is: why top has less processes than ps output. I didn't find the answer in the man pages.

Plus, if I were experienced like u, I wouldn't need posting in the forum.
 
Old 09-07-2010, 02:22 PM   #10
smoker
Senior Member
 
Registered: Oct 2004
Distribution: Fedora Core 4, 12, 13, 14, 15, 17
Posts: 2,279

Rep: Reputation: 250Reputation: 250Reputation: 250
Top doesn't have less processes. Top is designed to show the "top" consuming processes, according to how you sort the list. You can specify how many lines are shown, and what the list is sorted by. Your original question asked how to display the top processes consuming the cpu. That is what "top" was designed for. Showing the top processes consuming the most X.
 
  


Reply



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 On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
How to get %CPU usage of a process devershetty Linux - Newbie 1 08-18-2008 01:52 AM
How to get %CPU usage of a process devershetty Linux - Newbie 13 08-16-2008 11:51 AM
How to get %CPU usage of a process romydmisc Linux - Newbie 2 05-24-2006 01:02 PM
process cpu usage vanv101 Fedora 9 06-24-2005 05:53 PM
CPU usage of a process asharma Solaris / OpenSolaris 7 03-29-2003 02:17 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 06:20 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
Open Source Consulting | Domain Registration