From owner-freebsd-questions@FreeBSD.ORG Sun Dec 27 08:28:20 2009 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 2BBC11065679 for ; Sun, 27 Dec 2009 08:28:20 +0000 (UTC) (envelope-from m.seaman@infracaninophile.co.uk) Received: from smtp.infracaninophile.co.uk (gate6.infracaninophile.co.uk [IPv6:2001:8b0:151:1::1]) by mx1.freebsd.org (Postfix) with ESMTP id 80BEF8FC12 for ; Sun, 27 Dec 2009 08:28:19 +0000 (UTC) Received: from happy-idiot-talk.infracaninophile.co.uk (localhost [IPv6:::1]) (authenticated bits=0) by smtp.infracaninophile.co.uk (8.14.3/8.14.3) with ESMTP id nBR8SDHx046900; Sun, 27 Dec 2009 08:28:14 GMT (envelope-from m.seaman@infracaninophile.co.uk) X-DKIM: Sendmail DKIM Filter v2.8.3 smtp.infracaninophile.co.uk nBR8SDHx046900 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=infracaninophile.co.uk; s=200708; t=1261902494; bh=DzIjxLe+cPqPDHzmft4oqQbNUpUHH9jwHhGzFQHa+x4=; h=Message-ID:Date:From:MIME-Version:To:CC:Subject:References: In-Reply-To:Content-Type:Cc:Content-Type:Date:From:In-Reply-To: Message-ID:Mime-Version:References:To; z=Message-ID:=20<4B371A96.2020703@infracaninophile.co.uk>|Date:=20S un,=2027=20Dec=202009=2008:28:06=20+0000|From:=20Matthew=20Seaman= 20|Organization:=20Infracaninophi le|User-Agent:=20Thunderbird=202.0.0.23=20(X11/20091129)|MIME-Vers ion:=201.0|To:=20Manish=20Jain=20|CC:=2 0freebsd-questions@freebsd.org|Subject:=20Re:=20Looking=20for=20a= 20convenient=20way=20in=20C=20to=20retrieve=20CPU=20and=20memory=0 D=0A=20usage=20of=20a=20process|References:=20<4B37117C.3050502@gm ail.com>|In-Reply-To:=20<4B37117C.3050502@gmail.com>|X-Enigmail-Ve rsion:=200.95.6|Content-Type:=20multipart/signed=3B=20micalg=3Dpgp -sha256=3B=0D=0A=20protocol=3D"application/pgp-signature"=3B=0D=0A =20boundary=3D"------------enig9C1DB27BCC79CDC73FABD583"; b=MFKsVboACCRmBPIe1ovKCoGhrLMUw8QhAHcOMoH4Iznhtahcdr/BVygpQz2KnNJS1 KStqu7yxBC0AlF+/UVwblspQHm4npbL1MbBHdTH8Yy9N8QTN30Bv0wnZChIkSvZq8v tIUwygDXvusUpr4iZXzn5+4+Xg/DuRGyTjlf2+/A= X-Authentication-Warning: happy-idiot-talk.infracaninophile.co.uk: Host localhost [IPv6:::1] claimed to be happy-idiot-talk.infracaninophile.co.uk Message-ID: <4B371A96.2020703@infracaninophile.co.uk> Date: Sun, 27 Dec 2009 08:28:06 +0000 From: Matthew Seaman Organization: Infracaninophile User-Agent: Thunderbird 2.0.0.23 (X11/20091129) MIME-Version: 1.0 To: Manish Jain References: <4B37117C.3050502@gmail.com> In-Reply-To: <4B37117C.3050502@gmail.com> X-Enigmail-Version: 0.95.6 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="------------enig9C1DB27BCC79CDC73FABD583" X-Virus-Scanned: clamav-milter 0.95.3 at happy-idiot-talk.infracaninophile.co.uk X-Virus-Status: Clean X-Spam-Status: No, score=-2.9 required=5.0 tests=AWL,BAYES_00,DKIM_SIGNED, DKIM_VERIFIED,NO_RELAYS autolearn=ham version=3.2.5 X-Spam-Checker-Version: SpamAssassin 3.2.5 (2008-06-10) on happy-idiot-talk.infracaninophile.co.uk Cc: freebsd-questions@freebsd.org Subject: Re: Looking for a convenient way in C to retrieve CPU and memory usage of a process X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 27 Dec 2009 08:28:20 -0000 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--