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中的foreach复选框POST 2021-01-01
- PHPUnit 的 Selenium 2 文档到底在哪里? 2022-01-01
- Web 服务器如何处理请求? 2021-01-01
- 如何在数学上评估像“2-1"这样的字符串?产生“1"? 2022-01-01
- php中的PDF导出 2022-01-01
- php 7.4 在写入变量中的 Twig 问题 2022-01-01
- 主题化 Drupal 7 的 Ubercart “/cart"页 2021-01-01
- 使用 scandir() 在目录中查找文件夹 (PHP) 2022-01-01
- Yii2 - 在运行时设置邮件传输参数 2022-01-01
- 将变量从树枝传递给 js 2022-01-01