process cpu\memory usage

Asked by afzal


    I am searching for a C\C++ code to get cpu and memory usage by a single process...

Question information

English Edit question
Ubuntu linux-meta Edit question
No assignee Edit question
Last query:
Last reply:
Revision history for this message
Bhavani Shankar (bhavi) said :


I have no source but its simple..

If you are using C/C++ and libc, there are a few ways to do nearly what you want, but there is no magic function that will tell you what you want to know. The easiest ways is to read in the appropriate "files" in /proc. There's probably something much like you want in /proc/net, and also in /proc/sys/net, and other places. However, it's not a bad idea to just pipe to ps, since it's just scanning all of the processes that you're interested in anyway out of /proc, and then interpret the info it returns and format it for your own uses.

All of that should also be very straight forward. But no matter what you're going to have to do some scanning and formatting on your own to get the info you want.


Bhavani Shankar.

Can you help with this problem?

Provide an answer of your own, or ask afzal for more information if necessary.

To post a message you must log in.