• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

top and ps showing different results for cpu %

Red Squirrel

No Lifer
I noticed that top shows a different value for cpu use % as opposed to using ps. Has anyone ever noticed this, or am I maybe reading it wrong?

I wrote a simple php script that uses ps to display the resource usage of my VMs but then when I run top the results don't match at all. Thinking maybe my script was parsing wrong I typed ps and sure enough the results are different.
 
The ps man page says that, "CPU usage is currently expressed as the percentage of time spent running during the entire lifetime of the process. This is not ideal, and it does not conform to the standards that ps otherwise conforms to."

I didn't even know ps could display CPU usage %. I guess this is why nobody ever mentioned it.
 
Hmm that kind of sucks. Is there a way to get a top output in static format and sort it as well? (ex: a single command that returns to the promt)
 
Originally posted by: RedSquirrel
Hmm that kind of sucks. Is there a way to get a top output in static format and sort it as well? (ex: a single command that returns to the promt)

Depends on your platform. For me, its top -n 1
Try 'man top'
 
Back
Top