How to get per-process CPU utilization in Linux
This command returns the total CPU utilization of the specified process-name:
ps aux | grep process-name | awk '{sum += $3}; END {print sum}'
Breakdown of the command:
-
ps aux: get all processes and info -
grep process-name: filter all lines with the process name. Processes such ashttpdhave multiple workers. -
awk '{sum += $3}; END {print sum1}: add up CPU usage of all processes and print the sum.