ps and top give different CPU usage

This question is old, but in my opinion the answer is incorrect. ps and top calculates CPU usage using different methods.

from man top:

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

from man ps:

CPU usage is currently expressed as the percentage of time spent running during the entire lifetime of a process.

So, lets say you have a process that was started a week ago and during that time it used 2.2% of CPU time on average. If suddenly it would became CPU intensive ( constantly consuming 100%) - looking at ps you would observe same 2.2% for the first few hours.


The likeliest reason is that top shows the percentage values as a percentage of a single CPU while ps shows the percentage of total available CPU power. Try running top and hitting ShiftI while it's running to show the percentage of all cores.

If this is a server cluster with a lot of CPUs, what you describe is normal behavior. Also see here.

Tags:

Linux

Ps

Top