2

I want to write a program like system monitor. I want to have a list of programs with their process ID and usage of CPU and RAM. I know Linux writes this information in the /proc folder but somebody told me that I can use some functions to get it too. For example a program that will return a list like:

name  PID   RAM
sh    3904  72KIB

And I want to code in C++.

3
  • There a MANY programs out there already that do this. Most are open source. Go look at the source code. Commented Jul 12, 2011 at 4:28
  • @Chris could you please help me an give me a link?thanks
    – user787084
    Commented Jul 12, 2011 at 4:29
  • htop is a personal favorite of mine. Commented Jul 12, 2011 at 4:31

1 Answer 1

5

Why don't you look at the source code for top, which displays these and many more process statistics?

Here is the busybox version, which is comparatively short and simple. It gets the information by reading the proc filesystem, that logic is here.

2
  • thanks...it seems good.but can i how can i use it?it seems it is not standard library.could you please help me a bit?
    – user787084
    Commented Jul 12, 2011 at 6:02
  • @mimad: you can read pseudo-files from the Linux /proc/ filesystem using the standard library. To enumerate files there, use e.g. Boost.
    – MSalters
    Commented Jul 12, 2011 at 8:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.