X
    Categories: Linux

4 Awesome ways to find top CPU consuming processes in Linux.


Major part of sysadmin time goes into finding the cause of the load on the system eg. Finding processes which are consuming the resources. This post will help you with how to quickly find top CPU consuming processes in Linux.


1. Finding out  top CPU consuming processes in Linux using ps command.

There is one liner code available with ps command which will help you  to find top CPU consuming processes in Linux.

Command:

 ps -eo pid,ppid,cmd,%mem,%cpu --sort=-%cpu | head

Sample Output:

[root@rhel1 ~]# ps -eo pid,ppid,cmd,%mem,%cpu --sort=-%cpu | head
  PID  PPID CMD                         %MEM %CPU
23236 20520 dd if=/dev/zero of=/dev/nul  0.0 96.6
19509     1 /usr/bin/Xvnc :1 -desktop r  0.8  0.3
19559 19514 nautilus                     0.4  0.1
19668     1 /usr/lib64/firefox-3.6/fire  2.0  0.1
    1     0 /sbin/init                   0.0  0.0
    2     0 [kthreadd]                   0.0  0.0
    3     2 [migration/0]                0.0  0.0
    4     2 [ksoftirqd/0]                0.0  0.0
    5     2 [migration/0]                0.0  0.0
[root@rhel1 ~]#

2. Continuously monitoring top CPU consuming processes in Linux.

Lets say you don’t want single sample output of the command instead you want to monitor the output continuously. Yes you can do it using watch command as below:

Command:

[root@rhel1 ~]# watch "ps -eo pid,ppid,cmd,%mem,%cpu --sort=-%cpu | head"

Sample output:

Every 2.0s: ps -eo pid,ppid,cmd,%mem,%cpu --sort=-%cpu | head                                                                                   Sun Jan 15 05:40:32 2017

  PID  PPID CMD                         %MEM %CPU
23236 20520 dd if=/dev/zero of=/dev/nul  0.0 99.2
19509     1 /usr/bin/Xvnc :1 -desktop r  0.8  0.2
19559 19514 nautilus                     0.4  0.1
19668     1 /usr/lib64/firefox-3.6/fire  2.0  0.1
    1     0 /sbin/init                   0.0  0.0
    2     0 [kthreadd]                   0.0  0.0
    3     2 [migration/0]                0.0  0.0
    4     2 [ksoftirqd/0]                0.0  0.0
    5     2 [migration/0]                0.0  0.0

3. Top CPU consuming processes in Linux using top command.

The same output of the ps command can also be achieved using the native top command in linux to find top cpu consuming processes in Linux.

Command:

[root@rhel1 ~]# top -b -n 1 | head -n 12  | tail -n 6

Sample output:

[root@rhel1 ~]# top -b -n 1 | head -n 12  | tail -n 6
  PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND
23236 root      20   0  102m  672  568 R 100.0  0.0  12:43.07 dd
23377 root      20   0 15084 1184  848 R  2.0  0.0   0:00.01 top
    1 root      20   0 19396 1532 1228 S  0.0  0.0   0:01.34 init
    2 root      20   0     0    0    0 S  0.0  0.0   0:00.01 kthreadd
    3 root      RT   0     0    0    0 S  0.0  0.0   0:05.08 migration/0
[root@rhel1 ~]#

4. Find Top CPU consuming processes in Linux using htop command.

Like top command htop utility within linux which will help you to find the top cpu consuming processes in Linux.  To find it out use “htop” command.

Command:

[root@rhel1 ~]# htop

Once you fired htop command, a continuous running window will open same like top as below:

Now to sort out the processes by cpu utilization  simply press “F6” button and then select cpu and press enter. You will now see the processes sorted according to cpu utilization as below:

 

 

Related Post