I am running a test on Ubuntu 14.04. When I check my CPU usage using 'ps aux|grep service' then CPU usage is 0.1 of a process, while in htop for the same process the CPU% is 12.3.
Can anyone tell me the reason? or which value should I consider the right one?
Thanks
They are measuring different things.
From the ps
man-page:
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%.
From the htop
man-page (I am the author of htop
):
PERCENT_CPU (CPU%)
The percentage of the CPU time that the process is currently
using.
So, in htop
this is the percentage of total CPU time used by the program between the last refresh of the screen and now.
PercentageInHtop = (non-idle CPU time used by process during the last 1.5s) / 1.5s
In ps
this is the percentage of CPU time used by the program relative to the total time it exists (ie, since it was launched).
PercentageInPs = (non-idle CPU time used by process since process startup) / (time elapsed since process startup)
That is, in your reading it means that htop
is saying that the service is taking 12.3% of your CPU now, while ps
is saying that your service has spent 99.9% of its total life idle.