linux,

List processes with high memory usage in Linux

Sep 05, 2021 · 1 min read · Post a comment

There are situations where your web application or particular software installed on your machine takes a lot of time to load. The troubleshooting process may last long but however, you need to start with something. A good practice is to figure out which processes are taking a lot of memory on your machine.

In this tutorial, I’m going to show you how to sort out the top 20 processes that are memory hungry.

Prerequisites

  • Linux bash environment

Sort top 20 memory hungry processes

To list the processes that are taking a lot of memory, run:

ps aux | awk '{print $2, $3, $4, $11}' | sort -k3rn | head -n 20

Output:

PID  %CPU  %MEM  COMMAND
8726  5.1  12.9 /usr/lib/chromium-browser/chromium-browser
8645  6.4  5.0  /usr/lib/chromium-browser/chromium-browser
10028 2.6  3.3  /usr/lib/chromium-browser/chromium-browser
15417 16.7 3.0  /usr/lib/chromium-browser/chromium-browser
3467  4.5  2.5  /usr/bin/gnome-shell
8683  5.0  2.8  /usr/lib/chromium-browser/chromium-browser
8773  0.4  2.0  /usr/lib/chromium-browser/chromium-browser
14666 0.5  1.0  /usr/lib/chromium-browser/chromium-browser
14730 7.4  1.3  /usr/lib/chromium-browser/chromium-browser
1485  0.1  1.1  /usr/sbin/mysqld
15570 10.8 1.9  /usr/lib/chromium-browser/chromium-browser
1693  3.2  1.1  /usr/lib/xorg/Xorg
8457  0.0  1.2  /usr/bin/gnome-software
8787  1.4  1.4  /usr/lib/chromium-browser/chromium-browser
8796  0.7  1.1  /usr/lib/chromium-browser/chromium-browser
8960  0.3  1.0  /usr/lib/chromium-browser/chromium-browser
9005  0.2  1.1  /usr/lib/chromium-browser/chromium-browser
9060  2.2  1.8  /usr/share/code/code
9086  1.0  1.1  /usr/share/code/code
9092  0.3  1.4  /usr/share/code/code
  • sort -k3rn: sort command is used with the following parameters: -r , -n and the -k. That shows the output in reverse numeric order based on the memory, which can be found in the third column.
  • head -n 20: Will take the first 20 processes.

Conclusion

The command to list the memory-hungry processes is quite easy but is crucial to understand and determine the potential system issue. Feel free to leave a comment below and if you find this tutorial useful, follow our official channel on Telegram.