From owner-freebsd-questions@FreeBSD.ORG Sun Dec 27 08:32:41 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 42A9A106568B for ; Sun, 27 Dec 2009 08:32:41 +0000 (UTC) (envelope-from bf1783@googlemail.com) Received: from mail-ew0-f226.google.com (mail-ew0-f226.google.com [209.85.219.226]) by mx1.freebsd.org (Postfix) with ESMTP id 958538FC1A for ; Sun, 27 Dec 2009 08:32:40 +0000 (UTC) Received: by ewy26 with SMTP id 26so6511886ewy.3 for ; Sun, 27 Dec 2009 00:32:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=gamma; h=domainkey-signature:mime-version:received:date:message-id:subject :from:to:cc:content-type; bh=YF7GVRr9cxyTdz3bMicQVUN1SuBI1MMX1DiTtEwSqvo=; b=e5lLREb1fr5aruPyBQBXDCkTKNyoMW9Z2OhZ/ZsZQGCq7Ay1OZnHMoMP5MOzrMDoSb iQhm9PjVnMxnkFCGGwxVhKsI8HOKihq+H3ifuUONdBN7km1S2Bjyd90VSxuzyXNOET+m lWv6WZ7J+MJ3GYIsRScjGQputJFODBuCgNqAk= DomainKey-Signature: a=rsa-sha1; c=nofws; d=googlemail.com; s=gamma; h=mime-version:date:message-id:subject:from:to:cc:content-type; b=XGuQgC6VPkUjbNCkb95410o7RPVDWjTThpvCMuD24x2ZUH3SMtkKoDVBMKHxJWN7Pt X8wr+KJwRECw3JBTYYMHD364Br41tM9M+zTdzMUp2y9NpjHbCow1wnE+1EUwbmlazO7I eGcUcb2H1t8XSQihyc0OEfH0s3QNoGC4zhGFM= MIME-Version: 1.0 Received: by 10.216.90.65 with SMTP id d43mr1151478wef.41.1261902746413; Sun, 27 Dec 2009 00:32:26 -0800 (PST) Date: Sun, 27 Dec 2009 03:32:26 -0500 Message-ID: From: "b. f." To: Manish Jain Content-Type: text/plain; charset=ISO-8859-1 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:32:41 -0000 >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 ? Hmm. Portable, no /proc... ? It could be tough to do this generically. Why not look at unixtop, which tries to be portable?: http://sourceforge.net/projects/unixtop/files/ I think on FreeBSD it resorts to using kvm(3). You could just call that directly. Also, coming soon on FreeBSD, there will be libprocstat, which aims at making this easier: http://svn.freebsd.org/viewvc/base/projects/libprocstat/ stas@ is working on that. This kind of question is best suited for freebsd-hackers@ . Regards, b.