Debian:使用 bash 找出 CPU 使用率 [英] Debian: Find out CPU usage using bash

查看:77
本文介绍了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 使用率的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆