Debian: Find out CPU usage using bash(Debian:使用 bash 找出 CPU 使用率)
问题描述
我正在使用 PHP 来读取当前的 CPU 使用率.我在 vServer 上,所以 shell_exec 已启用.
I'm using PHP to read the current CPU usage. I'm on a vServer, so shell_exec is enabled.
我在 ps
上尝试过 grep
,但没有成功.如何使用 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
如果要直接询问操作系统,请使用 uptime
If you want to directly ask the OS, use uptime
$uptimeString = `uptime`;
或任何现有答案 如何在 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 使用率的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Debian:使用 bash 找出 CPU 使用率


- PHP Count 布尔数组中真值的数量 2021-01-01
- Mod使用GET变量将子域重写为PHP 2021-01-01
- 没有作曲家的 PSR4 自动加载 2022-01-01
- SoapClient 设置自定义 HTTP Header 2021-01-01
- Oracle 即时客户端 DYLD_LIBRARY_PATH 错误 2022-01-01
- 带有通配符的 Laravel 验证器 2021-01-01
- 如何定位 php.ini 文件 (xampp) 2022-01-01
- 从 PHP 中的输入表单获取日期 2022-01-01
- Laravel 仓库 2022-01-01
- 正确分离 PHP 中的逻辑/样式 2021-01-01