It has been asked a few times before on this forum, but none of the answers gave me a statisfying solution.
I want to make a function that returns the cpu usage in %. I can use getloadavg() which returns the load averages. But I dont want that because the loadavg can be bigger than 2 or 3 even with a single cpu.
#my_array=($(top -n 1))
Gives me a different output on each pc.
What is a reliable way to get the cpu usage in linux using C++ (or just the command-line)?