process cpu\memory usage

Asked by afzal on 2008-03-18

hi,

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

Question information

Language:
English Edit question
Status:
Answered
For:
Ubuntu linux-meta Edit question
Assignee:
No assignee Edit question
Last query:
2008-03-18
Last reply:
2008-03-18
Bhavani Shankar (bhavi) said : #1

Hello..

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.

Regards

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.