1753701 Members
5096 Online
108799 Solutions
New Discussion юеВ

Re: UNIX95 and pcpu

 
SOLVED
Go to solution
Kevin Liquori_1
Regular Advisor

UNIX95 and pcpu

I've written a script to trap CPU usage for particular processes. To do this I'm using ps with the UNIX95 option as:

UNIX95=1 ps -e -o pcpu,state,pid,ppid,comm

Is the pcpu column here the same percentage that I would see if I viewed that process in top and compared value under the %CPU column?

When I run them on the command line now they seem very close (timing isn't perfect) but I have a discrepancy between what I captured in my log and what a user reported while viewing top.

TIA

Kevin
4 REPLIES 4
James R. Ferguson
Acclaimed Contributor

Re: UNIX95 and pcpu

Hi Kevin:

I would choose your method and make comparisons using that method only. Personally, I would use 'ps' since it is scriptable as its underlying 'pstat()' interface (with C code).

Regards!

...JRF...
Kevin Liquori_1
Regular Advisor

Re: UNIX95 and pcpu

I'll definitely choose the one method, but am I correct in assuming that those two CPU outputs are presenting the same data?

For example, if the process run at 100% CPU for a sustained period both ps's pcpu and top's %CPU should reflect 100% (in an ideal situation).

Thanks again

Kevin
James R. Ferguson
Acclaimed Contributor
Solution

Re: UNIX95 and pcpu

Hi (again) Kevin:

> am I correct in assuming that those two CPU outputs are presenting the same data?

Yes, I believe that they are the same. From the 'ps' manpages 'pcpu' is the percentage of CPU time used by this process during the last scheduling interval. The 'top' manpages similarly say that the "%CPU" is the raw CPU percentage. Both values can only be values ascertained during a sampling interval.

Regards!

...JRF...
Kevin Liquori_1
Regular Advisor

Re: UNIX95 and pcpu

Excellent, thanks for your help.