Re: Looking for a convenient way in C to retrieve CPU and memory usage of a process

2009-12-27 Thread Matthew Seaman

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



signature.asc
Description: OpenPGP digital signature


Re: Looking for a convenient way in C to retrieve CPU and memory usage of a process

2009-12-27 Thread b. f.
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.
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org


Looking for a convenient way in C to retrieve CPU and memory usage of a process

2009-12-26 Thread Manish Jain


Hello,

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 ?



Thanks for any help.

Regards  Happy New Year
Manish Jain
invalid.poin...@gmail.com
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org