0

How can I get the total percentage or volume of memory usage and CPU consumption from within C++11 code on ubuntu (or any other linux-based system)?

The usage I want to get is for the whole system, not just for current thread or process.

3

1 Answer 1

0

Read about proc(5) and use /proc/meminfo. You can open it and read it as a sequential file (even if it often behaves as a pipe; e.g. it is not seekable).

Of course, this is Linux specific.

And you might scan the /proc/ directory (using opendir(3), readdir(3), closedir) for directories starting with a digit, and read each of their /proc/1234/maps or /proc/1234/status - these correspond to process 1234)

Read also linuxatemyram

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.