Welcome to the Linux Foundation Forum!

Calculate CPU Performance by C Code

How can i calculate percentage cpu and memory usage in linux through C code.

I want to know cpu and memory usage for whole system


  • I'm not sure if this is the way you're intending, but you could run the "system()" function in your program with the "lscpu" command:

    system("lscpu | grep -E \"(MHz|family|MIPS|L1d|l1i|L2|L3|stepping)\"");

    I hope this helps!


Upcoming Training