[英]CPU Usage from a file on Linux
I have to get the cpu usage on Linux from a file located on my hard drive. 我必须从我硬盘上的文件中获取Linux上的cpu用法。 But after some research about it, I didn't find a proper file which informs me about the CPU usage.
但经过一些研究后,我没有找到一个适当的文件告诉我CPU的使用情况。
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. 如果您知道一个文件,那就太棒了,谢谢。
This sort of information is available under the /proc
filesystem. 这种信息在
/proc
文件系统下可用。 See man proc
. 见
man proc
。
In particular: 尤其是:
/proc/loadavg
gives load averages; /proc/loadavg
给出平均负载; /proc/stat
gives information on the amount of time the system spent in user/kernel mode, etc (thanks @Mat!) /proc/stat
提供有关系统在用户/内核模式下花费的时间等信息(感谢@Mat!) /proc/[pid]/stat
contains information on CPU times for the given process. /proc/[pid]/stat
包含有关给定进程的CPU时间的信息。 man proc
will give further details. man proc
将提供进一步的细节。
您可以使用/proc/loadavg
来确定文件的负载。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.