LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 02-24-2012, 08:43 PM   #1
mrme
LQ Newbie
 
Registered: Feb 2012
Distribution: Ubuntu
Posts: 2

Rep: Reputation: Disabled
CPU usage by processes using top command


Guys,

I'm new here so forgive my ignorance if I'm missing something here.

Wonder if someone can help me here, or point me to the right rtfm :-)


I'm using top command to determine total cpu utilization by applications. If you look at below top output, you can see CPU is 52.4% utilized.

i.e. 9.7 + 9.1 + 0.7 + 1.2 + 31.7 = 52.4% and including the idle (47.5 + 52.4 = 99.9%) would give you the total CPU - still not sure why 0.1 is missing


Code:
  top - 20:39:33 up 28 min,  1 user,  load average: 12.38, 10.38, 6.31
Tasks: 311 total,  17 running, 294 sleeping,   0 stopped,   0 zombie
Cpu(s):  9.7%us,  9.1%sy,  0.0%ni, 47.5%id,  0.7%wa,  1.2%hi, 31.7%si,  0.0%st
Mem:  33012208k total,  3576120k used, 29436088k free,    31988k buffers
Swap:        0k total,        0k used,        0k free,   485704k cached
There are 8 CPUs/Cores so total CPU percentage would be 100x8 = 800%.

Now I have a custom script that's keeping the CPUs busy

Code:
PID   USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND            
44367 root      19  -1  2720  844  728 R 48.4  0.0   0:02.05 myscript
44365 root      19  -1  2720  848  728 R 46.9  0.0   0:02.35 myscript
44448 root      19  -1  2720  844  728 R 43.9  0.0   0:01.78 myscript
44665 root      19  -1  2720  844  728 R 43.9  0.0   0:00.96 myscript
44772 root      19  -1  2720  848  728 R 43.9  0.0   0:00.29 myscript
54460 mrme      19  -1 1587m  54m 2992 R 36.3  0.2   7:51.67 myscript
54462 mrme      19  -1 1586m  53m 2992 R 34.8  0.2   7:15.12 myscript
54463 mrme      19  -1 1587m  54m 2992 R 34.8  0.2   7:58.44 myscript
54461 mrme      19  -1 1586m  54m 2992 R 33.3  0.2   7:26.50 myscript
54464 mrme      19  -1 1587m  54m 2992 R 31.8  0.2   7:37.07 myscript
54465 mrme      19  -1 1587m  54m 2992 S 31.8  0.2   7:24.34 myscript
54466 mrme      19  -1 1587m  54m 2992 R 31.8  0.2   7:40.44 myscript
54459 mrme      19  -1 1588m  55m 3036 R 30.2  0.2   7:10.97 myscript
 3342 root      18  -2 34596  18m 1872 S 27.2  0.1   0:39.38 myscript
 4332 root      18  -2 40252  19m 1956 S 13.6  0.1   2:12.55 myscript
44760 root      20   0 19132 1300  824 R  7.6  0.0   0:00.13 top -c -b -n 1     
54458 root      19  -1 34184  19m 1560 S  6.0  0.1   0:45.39 monitor.pl       
   25 root      15  -5     0    0    0 S  3.0  0.0   0:06.60 [ksoftirqd/7]      
54455 root      19  -1 1599m  54m 2844 S  3.0  0.2   0:10.42 myscript
   16 root      15  -5     0    0    0 S  1.5  0.0   0:10.23 [ksoftirqd/4]      
 4716 root      19  -1  161m 101m  74m S  1.5  0.3   0:03.74 script2.sh
    1 root      20   0 10320  672  572 S  0.0  0.0   0:41.31 init [3]

If I sum up the CPU usage for all the processes (myscript) that would be:

48.4 + 46.9 + 43.9 + 43.9 + 43.9 + 36.3 + 34.8 + 34.8 + 33.3 + 31.8 + 31.8 + 31.8 + 30.2 + 27.2 + 13.6 + 7.6 + 6.0 + 3.0 + 3.0 + 1.5 + 1.5 = 555.2%

That means that the processes are using 555.2% of 800% CPU (correct me if I'm doing it wrong) In another words, it's 69.4% of the total CPU usage. But top's top shows that total CPU utilization is 52.4% why is there a difference of 17%? Which one should I trust, the total top calculated value or the total average processes usage? which one is accurate?

I'm not saying that the top is buggy, but I'm sure there's something I'm missing, whether it's the top refresh cycle or something else I need to know?


Would greatly appreciate your help.

Last edited by mrme; 02-24-2012 at 08:52 PM.
 
Old 02-24-2012, 09:13 PM   #2
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 21,140

Rep: Reputation: 4123Reputation: 4123Reputation: 4123Reputation: 4123Reputation: 4123Reputation: 4123Reputation: 4123Reputation: 4123Reputation: 4123Reputation: 4123Reputation: 4123
Welcome to the vagaries of sampling monitors.

Let's start at the beginning - how (exactly) did you produce that top listing.
 
Old 02-24-2012, 09:52 PM   #3
mrme
LQ Newbie
 
Registered: Feb 2012
Distribution: Ubuntu
Posts: 2

Original Poster
Rep: Reputation: Disabled
Actually this was taken from a production box, and the 'command' column had the actual long&ugly commands, so I had to just rename it 'myscript'.

The box is handling thousands of connections per second, 'myscript' is handling those connections (http),

the output is the result of 'top -c -b -n 1'


My point here is why does the total sum of the CPU usage of all the processes greater than the actual CPU utilization as shown in top header.


Thanks
 
Old 02-24-2012, 10:36 PM   #4
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 21,140

Rep: Reputation: 4123Reputation: 4123Reputation: 4123Reputation: 4123Reputation: 4123Reputation: 4123Reputation: 4123Reputation: 4123Reputation: 4123Reputation: 4123Reputation: 4123
I would suggest you (re-)read the manpage - particularly the bit in "BUGS". Then you will understand why I asked.
 
  


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



Similar Threads
Thread Thread Starter Forum Replies Last Post
Warning in Top 10 cpu consuming processes pinga123 Linux - Newbie 13 08-11-2010 07:19 AM
[SOLVED] listing cpu usage with top command dave12 Linux - Newbie 8 04-16-2010 07:13 AM
processes/CPU Usage/Mem Usage desktop wallpaper ceantuco Linux - Newbie 2 04-13-2009 01:14 PM
Finding the top CPU-using processes? "top" command does not help... catalytical Linux - Server 1 04-06-2009 04:50 PM
Other than top command which cmd is used to find the cpu usage and disk space sathish80 Linux - Newbie 2 11-15-2006 12:43 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 01:37 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