ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I want to get some informtion of system by C/C++ Language, such as:
1. CPU (These are percentages of total CPU time)
us: user time
sy: system time
id: idle time
2. Procs
r: The number of processes waiting for run time.
b: The number of processes in uninterruptable sleep.
w: The number of processes swapped out but otherwise runnable.
I have traced the source code of "vmstat", and it is too complex to understand.
first of all ,C language does not provide any funtion like this.
Maybe you can find or write a library to do the tasks upon.
I think you should find them in the kernel struct although it is not the best way.And the entries you want is served more to the kernel ,not to the user,so it is hard to find a function.
/proc directory indeed.
use a c++ istream to open and read /proc/loadavg. That'd give you the load values.
you can use turnips way to get the process info.
I trace the source code of procps package (including vmstat.c, sysinfo.c...) finally
But I still don't understand that the algorithm of code and the equation which calculate the sysytem information value.
Now, I copy some part of codes from the package, and I can get the information which I need now.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.