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 so开发者_如何学Gome 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++.
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.
精彩评论