Debian的:使用bash找出CPU使用率 [英] Debian: Find out CPU usage using bash
本文介绍了Debian的:使用bash找出CPU使用率的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用PHP读取当前CPU使用率。我在一个虚拟服务器,所以了shell_exec被启用。
I'm using PHP to read the current CPU usage. I'm on a vServer, so shell_exec is enabled.
我曾尝试的grep
在 PS
,但没有奏效。
我如何使用bash读取当前%的CPU使用率?
I have tried grep
on ps
, but it didn't work.
How can I read the current % CPU usage using bash?
推荐答案
最简单的方法就是使用的 sys_getloadavg
The easiest way is simply to use sys_getloadavg
如果您想直接问OS,使用运行时间
If you want to directly ask the OS, use uptime
$uptimeString = `uptime`;
或任何<一个href=\"http://stackoverflow.com/questions/1332861/how-can-i-determine-the-current-cpu-utilization-from-the-shell\">existing 的答案要怎么做同样的事情在bash,只是在反引号包裹。
Or any of the existing answers to how to do exactly the same thing in bash and just wrap in backticks.
这篇关于Debian的:使用bash找出CPU使用率的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文