CPU user/kernel time given the PID
David Wolfskill
david at catwhisker.org
Sun Mar 8 19:03:16 PDT 2009
On Sun, Mar 08, 2009 at 08:33:27PM -0400, Jay Loden wrote:
> Oliver Fromme wrote:
> > ps(1) and top(1) both use ki_pctcpu, see the getpcpu()
> > function in src/bin/ps/print.c and format_next_process()
> > in src/usr.bin/top/machine.c
>
> Hi Oliver, thanks for the reply. I noticed the same after some digging through
> the source code for ps and top. While CPU usage % is a useful number also, I was
> hoping to be able to get CPU time(s). Possibly that information simply isn't
> available on FreeBSD like it is for other OSes.
Have you checked to see if you can make use of the information provided
by procfs(5)? In particular, I note:
...
status The process status. This file is read-only and returns a single
line containing multiple space-separated fields as follows:
o command name
o process id
...
o the process start time in seconds and microseconds, comma
separated.
o the user time in seconds and microseconds, comma separated.
o the system time in seconds and microseconds, comma separated.
o the wait channel message
....
Thus, on my laptop, I see:
g1-35(6.4-S)[1] cat /proc/`pgrep firefox-bin`/status
firefox-bin 1735 1730 1549 1454 - noflags 1236526247,367664 3289,390208 477,843140 -kse- 1001 1001 1001,1001,1001,0,20,68,69,1004 -
g1-35(6.4-S)[2]
So above-listed items would be:
* firefox-bin
* 1735
...
* 1236526247,367664
* 3289,390208
* 477,843140
* -kse-
* -kse-
....
Granted, not every machine will necessarily have PROCFS in the
kernel configuration, but it is in GENERIC.
> ...
Peace,
david
--
David H. Wolfskill david at catwhisker.org
Depriving a girl or boy of an opportunity for education is evil.
See http://www.catwhisker.org/~david/publickey.gpg for my public key.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 195 bytes
Desc: not available
Url : http://lists.freebsd.org/pipermail/freebsd-hackers/attachments/20090309/f1813e19/attachment.pgp
More information about the freebsd-hackers
mailing list