user787084
user787084

Reputation:

Get RAM and CPU usage for process in Linux with C++

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++.

Upvotes: 2

Views: 4678

Answers (1)

Ben Voigt
Ben Voigt

Reputation: 283793

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.

Upvotes: 5

Related Questions