How can I determine the current CPU utilization from the shell? [closed]
Solution 1:
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.
Solution 2:
You can use top or ps commands to check the CPU usage.
using top : This will show you the cpu stats
top -b -n 1 |grep ^Cpu
using ps: This will show you the % cpu usage for each process.
ps -eo pcpu,pid,user,args | sort -r -k1 | less
Also, you can write a small script in bash or perl to read /proc/stat and calculate the CPU usage.