Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CPU Usage from a file on Linux

I have to get the cpu usage on Linux from a file located on my hard drive. But after some research about it, I didn't find a proper file which informs me about the CPU usage.

The best solution would be to find the file which contains these information and updated frequently.

If you know one file which make this, it would be great, thank you.

like image 921
Jeffrey Muller Avatar asked Dec 28 '22 07:12

Jeffrey Muller


1 Answers

This sort of information is available under the /proc filesystem. See man proc.

In particular:

  • /proc/loadavg gives load averages;
  • /proc/stat gives information on the amount of time the system spent in user/kernel mode, etc (thanks @Mat!)
  • /proc/[pid]/stat contains information on CPU times for the given process.

man proc will give further details.

like image 58
NPE Avatar answered Jan 08 '23 00:01

NPE