Difference between nice ps and top commands
Alan McKinnon
alan at linuxholdings.co.za
Thu Jun 15 21:14:44 UTC 2006
On Thursday 15 June 2006 10:01, neil al wrote:
> Hi,
>
> May I know what is the difference between the 'nice ps -eo
> pid,user,time,%cup%' and 'top' command. For example when i run a
> tomcat servlet container the nice ps -eo pid,user,time,%cup%
> command will print java process has a very large cpu usage and on
> the other hand, when try the top command the java process has
> little or no cpu usage. Both commands have different output values.
ps and top are not displaying the same thing, even though the use the
same name for them.
From the ps man page:
CODE HEADER DESCRIPTION
%cpu %CPU cpu utilization of the process in "##.#" format.
Currently, it is the CPU time used divided by the time
the process has been running (cputime/realtime ratio),
expressed as a percentage. It will not add up to 100%
unless you are lucky. (alias pcpu).
From the top man page:
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.
So ps calculates cpu usage by using the entire time the process has
been running giving a broad average over time. top considers only the
last second (by default), which can be very different from the ps
value under heavy load.
Analogy: consider a Formula 1 car. It does 200mph down the main
straight - this is top. It also covers the 200 mile race in 1h30min,
and average of 133 mph - this is ps
--
If only me, you and dead people understand hex,
how many people understand hex?
Alan McKinnon
alan at linuxholdings dot co dot za
+27 82, double three seven, one nine three five
More information about the ubuntu-users
mailing list