LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Server (https://www.linuxquestions.org/questions/linux-server-73/)
-   -   top and ps (https://www.linuxquestions.org/questions/linux-server-73/top-and-ps-940393/)

graziano1968 04-18-2012 02:23 AM

top and ps
 
Hello

I am monitoring clamd (clamAV antivirus usage) . If I use top I receive this

28562 root 25 0 381m 317m 2076 R 100 8.0 0:41.35 clamd

100% cpu usage due to clamd

If in the same time I execute this ps command
ps aux | grep "clamd"
root 28562 6.1 8.1 392088 330376 ? Ssl 02:07 0:41 /usr/sbin/clamd

6.1% cpu usage used by clamd

Which is correct , ps which is reporting 6.1% or top which is reporting 100% ?

I have an Intel Xeon E5430 @ 2.66GHz with 8 cores .


Thank you
Graziano

pan64 04-18-2012 02:45 AM

I assume top displays 100% of one core, ps displays 6.1% of the full capacity.

syg00 04-18-2012 02:57 AM

They are both correct.
Understand what you are measuring before even considering comparing the results. Top, when run interactively, displays interval usage - "ps" displays usage since process start.
Potentially vastly different - especially on multi-cores.

graziano1968 04-18-2012 03:09 AM

Quote:

Originally Posted by syg00 (Post 4655861)
They are both correct.
Understand what you are measuring before even considering comparing the results. Top, when run interactively, displays interval usage - "ps" displays usage since process start.
Potentially vastly different - especially on multi-cores.

So , if I want to know the "current" usage , top should be better , am I correct ? But , is it 100% of a single core , right ?

syg00 04-18-2012 03:18 AM

Yes - it is not normalized.
For multi-threaded apps, it is not uncommon to see several hundred percent reported.

pan64 04-18-2012 03:19 AM

see man top:
k: %CPU -- CPU usage
The task's share of the elapsed CPU time since the last screen update, expressed as a percentage of total CPU time. In a true SMP environment, if 'Irix mode' is Off, top will operate in 'Solaris mode' where a task's cpu usage will be divided by the total number of CPUs. You toggle 'Irix/Solaris' modes with the 'I' interactive command.

graziano1968 04-18-2012 03:51 AM

Quote:

Originally Posted by syg00 (Post 4655892)
Yes - it is not normalized.
For multi-threaded apps, it is not uncommon to see several hundred percent reported.

Clamd should not be a multi-threaded app. So 100% should be "100% single core" .

graziano1968 04-18-2012 04:03 AM

Quote:

Originally Posted by pan64 (Post 4655894)
see man top:
k: %CPU -- CPU usage
The task's share of the elapsed CPU time since the last screen update, expressed as a percentage of total CPU time. In a true SMP environment, if 'Irix mode' is Off, top will operate in 'Solaris mode' where a task's cpu usage will be divided by the total number of CPUs. You toggle 'Irix/Solaris' modes with the 'I' interactive command.

interesting .. using "I" all the values are divided by 8 which is the number of my cores , thank you.
BTW I was thinking top was doing this automatically .

graziano1968 04-18-2012 04:06 AM

Quote:

Originally Posted by syg00 (Post 4655861)
They are both correct.
"ps" displays usage since process start..

I read ps documentation , and truly I can't see that the values are a medium since the process start. However
do you think possible to receive current usage (not from the start) using ps ?

pan64 04-18-2012 04:14 AM

man ps see NOTES:
CPU usage is currently expressed as the percentage of time spent
running during the entire lifetime of a process. This is not ideal,
and it does not conform to the standards that ps otherwise conforms to.
CPU usage is unlikely to add up to exactly 100%.


but unfortunately it may slightly differ on some linux.

graziano1968 04-18-2012 04:16 AM

Quote:

Originally Posted by pan64 (Post 4655894)
see man top:
k: %CPU -- CPU usage
The task's share of the elapsed CPU time since the last screen update, expressed as a percentage of total CPU time. In a true SMP environment, if 'Irix mode' is Off, top will operate in 'Solaris mode' where a task's cpu usage will be divided by the total number of CPUs. You toggle 'Irix/Solaris' modes with the 'I' interactive command.


do you think possible to toggle Irix/Solaris when the interactive mode is off

for example
# top -n1 | grep "clamd"

however I would have Irix

pan64 04-18-2012 04:30 AM

Quote:

Originally Posted by graziano1968 (Post 4655941)
do you think possible to toggle Irix/Solaris when the interactive mode is off

see the man page:

Startup Defaults

The following startup defaults assume no configuration file, thus no user customizations. Even so, items shown with an asterisk ('*') could be overridden through the command-line.

Global_defaults 'A' - Alt display Off (full-screen) * 'd' - Delay time 3.0 seconds 'I' - Irix mode On (no, 'solaris' smp) * 'p' - PID monitoring Off * 's' ...

I can be only toggled using interactive mode


All times are GMT -5. The time now is 01:41 PM.