Monday, October 17, 2016

See Which Process is Using Most of Your CPU on Linux

To view the processes that are using your CPU use the following command,

sudo ps aux | awk '{print $2 " " $3}' | sort -k 2,2 -nr | grep -v 0.0 | grep -v %CPU
3656 1.5
1963 1.4
3634 0.4
2548 0.3
3251 0.1
3247 0.1
1 0.1

The first column is the PID(process ID) and the second column is the percentage of CPU used by that process.

If you want to view only the process that is using most of the CPU, you can use the following command,

sudo ps aux | awk '{print $2 " " $3}' | sort -k 2,2 -nr | grep -v 0.0 | grep -v %CPU | head -n 1
3656 1.5

Here 3656 is the PID(process ID) and it is using 1.5% of the CPU. On a real server, percentage of CPU usage might be way higher than that.

No comments:

Post a Comment