How can I determine the current CPU utilization from the shell in Linux?
For example, I get the load average like so:
cat /proc/loadavg
Outputs:
0.18 0.48 0.46 4/234 30719
CPU utilization refers to a computer's usage of processing resources, or the amount of work handled by a CPU. Actual CPU utilization varies depending on the amount and type of managed computing tasks. Certain tasks require heavy CPU time, while others require less because of non-CPU resource requirements.
The ps command command displays every process ( -e ) with a user-defined format ( -o pcpu ). First field is pcpu (cpu utilization). It is sorted in reverse order to display top 10 CPU eating process.
Linux does not have any system variables that give the current CPU utilization. Instead, you have to read /proc/stat
several times: each column in the cpu(n)
lines gives the total CPU time, and you have to take subsequent readings of it to get percentages. See this document to find out what the various columns mean.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With