How can I get a process usage using glibc ( getrusage() ) functions ?

It is always possible to fetch different information about a process from “/proc/” filesystem. I can point some important files from “/proc” filesystem to get statistics about a process.

/proc/pid/stat
/proc/pid/statm
/proc/pid/status

You can substitute the “pid” of the process in above and get the status of a process.

I can see some of the above files does not have proper tag to understand the information.

So you can use #man 5 proc command for interpreting proc information .

Using “glibc” fuctions can be an another way to fetch the some information.

I just thought of getting information about “context swithes of a process” using “getrusage()” in my fedora 12 system.

Below is a “C” program to get this information on the same binary.

Above program can be extended as you wish 🙂

Leave a Reply

Your email address will not be published. Required fields are marked *