Date: Sun, 27 Dec 2009 08:28:06 +0000 From: Matthew Seaman <m.seaman@infracaninophile.co.uk> To: Manish Jain <invalid.pointer@gmail.com> Cc: freebsd-questions@freebsd.org Subject: Re: Looking for a convenient way in C to retrieve CPU and memory usage of a process Message-ID: <4B371A96.2020703@infracaninophile.co.uk> In-Reply-To: <4B37117C.3050502@gmail.com> References: <4B37117C.3050502@gmail.com>
next in thread | previous in thread | raw e-mail | index | archive | help
This is an OpenPGP/MIME signed message (RFC 2440 and 3156) --------------enig9C1DB27BCC79CDC73FABD583 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: quoted-printable Manish Jain wrote: > I am looking for a convenient way using C to retrieve the current CPU=20 > and memory utilization of a process of which I have the pid. Can=20 > 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= =20 > information via the /proc filesystem. >=20 > I would be grateful if you could also please mention whether the=20 > suggested method[s] is/are FreeBSD-specific or would be portable to=20 > other environments like Solaris/Linux ? Use the source, Luke. In this cse, probably a very good place to start i= s with top(1) since it already does a lot of what you want. Start with=20 /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 --=20 Dr Matthew J Seaman MA, D.Phil. 7 Priory Courtyard Flat 3 PGP: http://www.infracaninophile.co.uk/pgpkey Ramsgate Kent, CT11 9PW --------------enig9C1DB27BCC79CDC73FABD583 Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.14 (FreeBSD) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org iEYEAREIAAYFAks3Gp0ACgkQ8Mjk52CukIxggQCfaYunvIbv0J+g6slQZtZmLyrd /uwAn3EzwJxky0YdPCp01169071KWS/T =IEP8 -----END PGP SIGNATURE----- --------------enig9C1DB27BCC79CDC73FABD583--
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?4B371A96.2020703>