Manish Jain wrote:

I am looking for a convenient way using C to retrieve the current CPU and memory utilization of a process of which I have the pid. Can somebody please give me a hint of which system-calls/library-functions to use for this ? I don't want to use the system() function or grep for information via the /proc filesystem.

I would be grateful if you could also please mention whether the suggested method[s] is/are FreeBSD-specific or would be portable to other environments like Solaris/Linux ?

Use the source, Luke.  In this cse, probably a very good place to start is
with top(1) since it already does a lot of what you want. Start with /usr/src/contrib/top/

This sort of thing generally requires reading /dev/kmem, which is very OS
dependent.  The same sort of approach will probably work on most Unix-oid
OSes, but the details will be significantly different.

        Cheers,

        Matthew

--
Dr Matthew J Seaman MA, D.Phil.                   7 Priory Courtyard
                                                 Flat 3
PGP: http://www.infracaninophile.co.uk/pgpkey     Ramsgate
                                                 Kent, CT11 9PW

Attachment: signature.asc
Description: OpenPGP digital signature

Reply via email to