4 ways to find the most memory-consuming processes in Linux

In our previous article, we discussed how to find the busiest CPU processes in Linux. Now it’s time to find the most memory consuming processes in Linux. This article will help you quickly find the most memory consuming processes on Linux.

1. Find out the processes consuming the most memory in Linux using the ps command.

There is one code available using the ps command to help you find the most memory consuming processes on Linux.

Team:

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

Output example:

[email protected]:~# top -o %MEM -b -n 1|head -n 12|tail -6                                                                                                       
  PID USER      PR  NI    VIRT    RES    SHR S  %CPU %MEM     TIME+ COMMAND                                                                                   
 1002 mysql     20   0 2152916 566836   9608 S   0.0 18.4  13:04.02 mysqld                                                                                    
  828 clamav    20   0  773404 543596   6716 S   0.0 17.6   1:00.62 clamd                                                                                     
 1212 root      20   0 1320544  52584  21032 S   0.0  1.7   0:49.04 core                                                                                      
 1097 root      20   0  468248  20604  19304 S   0.0  0.7   0:02.25 apache2                                                                                   
 1329 www-data  20   0  404428  20132  15144 S   0.0  0.7   0:00.43 php-fpm7.0                                                                                
[email protected]:~#

Here you will get sorted by memory usage, which will help you find out the processes consuming the most memory on Linux very easily.

2. Constant monitoring of processes in memory in Linux.

If you need to monitor output continuously. The watch command example below is very handy.

Team:

# watch "ps -eo pid,ppid,cmd,%mem --sort=-%mem | head"

Output example:

[email protected]:~# watch "ps -eo pid,ppid,cmd,%mem --sort=-%mem | head"
Every 2.0s: ps -eo pid,ppid,cmd,%mem --sort=-%mem | head                                                                              Tue Sep 12 14:42:11 2017
                                                                                                                                                              
  PID  PPID CMD                         %MEM                                                                                                                  
 1002     1 /usr/sbin/mysqld            18.4                                                                                                                  
  828     1 /usr/sbin/clamd --foregroun 17.6                                                                                                                  
23270 23269 /usr/bin/php-cgi /var/www/p  3.5                                                                                                                  
 1212     1 bin/core ispmgr              1.7                                                                                                                  
 1097     1 /usr/sbin/apache2 -k start   0.6                                                                                                                  
 1329  1062 php-fpm: pool www-data       0.6                                                                                                                  
 1080  1062 php-fpm: pool www-data       0.6                                                                                                                  
 1062     1 php-fpm: master process (/e  0.5                                                                                                                  
  971     1 /usr/sbin/named -f -u bind   0.5

3. Identify the most memory consuming processes on Linux using the top command.

The same ps command output can also be achieved using the native Linux top command.

Team:

# top -o %MEM -b -n 1|head -n 12|tail -6

Output example:

[email protected]:~# top -o %MEM -b -n 1|head -n 12|tail -6                                                                                                       
  PID USER      PR  NI    VIRT    RES    SHR S  %CPU %MEM     TIME+ COMMAND                                                                                   
 1002 mysql     20   0 2152916 567100   9608 S  60.0 18.4  13:05.07 mysqld                                                                                    
  828 clamav    20   0  773404 543596   6716 S   0.0 17.6   1:00.62 clamd                                                                                     
23448 destroyer  20   0  435360 120668  59364 R  40.0  3.9   0:01.76 php                                                                                       
 1212 root      20   0 1320544  53068  21436 S   0.0  1.7   0:49.23 core                                                                                      
 1097 root      20   0  468248  20604  19304 S   0.0  0.7   0:02.25 apache2                                                                                   
[email protected]:~#

4. Using the htop command.

There is another utility called htop that can help you find the most memory consuming processes on Linux.

Team:

[[email protected] ~]# htop

After executing the htop command, a window with continuous data output will open, as shown below:

In order to understand the processes of using memory, simply press the “F6” button, and then select memory and press ENTER. You can see the processes sorted by memory usage as shown below:

4 ways to find the most memory-consuming processes in Linux

Sidebar