Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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

share|improve this question
    
top usually divides actual value by number of cores (CPUs). Press '1' to see values per core. –  tigran Jul 20 '12 at 9:05
add comment

2 Answers 2

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.

share|improve this answer
add comment

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

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.