4

I find it difficult to understand the output produced by ps and top?

This is the output by top:

PID    PSID USERNAME  TID  PRI NICE  SIZE  RES  STATE  TIME    CPU   COMMAND
26439 23712 soumyau  26439  15    0 7512M 5234M sleep 286:25  16.67% or_lse2 (18)
26523 23712 soumyau  26439  -2    0 7512M 5234M cpu9  143:10   8.33% or_lse2
26522 23712 soumyau  26439  -2    0 7512M 5234M cpu3  143:10   8.33% or_lse2

This is by ps (ps -L -p 26439 -o pcpu,psr,pid,user,tid):

%CPU  PSR   PID   USER       TID
99.9   3   26439 soumyau    26522
99.9   9   26439 soumyau    26523
0.0    8   26439 soumyau    26439

Why are there differences in two result?

Can you briefly explain the significance of the two CPU% ?

1
  • top usually divides actual value by number of cores (CPUs). Press '1' to see values per core.
    – kofemann
    Jul 20, 2012 at 9:05

3 Answers 3

6

ps is based on the accumulate CPU usage (since the process started), where the %CPU is an average (total/time).

top reports the (average) CPU usage since the last time it was sampled.

For reference, see this snippet from man ps

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%.

and from man top

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.

1

The difference is really only in if it is divided by number of cores or not.

basically ps shows output NOT divided by number of cores
instead of top that can operate in two modes
press:

[SHIFT]+[I]
to toggle to/from Irix mode
and/or you will see the same numbers like in ps

0

'ps' command showing all process by time wise. which is having the all process. Its not care about the process state (running or sleeping).

'top' command showing running process in the top order. That's why you can see the variation in the output. Some of the process in the first line after some time it will go second or third its dependences on the process status.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .