I'm using PHP to read the current CPU usage. I'm on a vServer, so shell_exec is enabled.
I have tried grep
on ps
, but it didn't work.
How can I read the current % CPU usage using bash?
I'm using PHP to read the current CPU usage. I'm on a vServer, so shell_exec is enabled.
I have tried grep
on ps
, but it didn't work.
How can I read the current % CPU usage using bash?
After taking a closer look at all solutions, I came up with this code:
It calls
ps -aux
and sums up the CPU %.The easiest way is simply to use sys_getloadavg
If you want to directly ask the OS, use uptime
Or any of the existing answers to how to do exactly the same thing in bash and just wrap in backticks.