Both top and ps show a %CPU column, but they count it over different periods. Mix them up and you will blame a process that went quiet long ago.
top recalculates %CPU on every screen refresh, over the last three seconds. That is why it shows who keeps the CPU busy right now. How much CPU time a process has used over its whole life top shows in the TIME+ column.
ps divides that accumulated time by the whole lifetime of the process. A process that worked nonstop an hour ago and sleeps now shows a noticeable %CPU in ps and zero in top.
Above the list, top prints a summary. The Tasks line says how many processes there are in total and how many of them are running, sleeping, and stopped.
A nightly export ran nonstop for an hour and is now waiting. What will ps and top show under %CPU?
-
top counts %CPU over the last three seconds, and the process slept through them. Only
ps, which counts over the process's whole life, shows a noticeable share. -
The other way round: top looks at the last few seconds, when the process slept, and
pslooks at its whole life, which includes the hour of work. -
psdivides the CPU time a process has used by its whole lifetime, so an hour of work leaves a noticeable %CPU. top shows zero, since it counts the last few seconds.
ps divides a process's CPU time by its whole lifetime, while top divides by the last few seconds between refreshes. That is why you look at top to see who keeps the CPU busy right now.
Key points
- top counts %CPU over the last few seconds, so it shows who keeps the CPU busy right now.
-
psdivides CPU time by the whole lifetime of a process, so it remembers past load.