How to see top processes sorted by actual memory usage on Linux?

Linux provides the famous top command utility that displays information about running processes, including their process IDs, CPU usage, and memory consumption. However, the default output is not sorted by memory usage, and the display order changes frequently as processes consume different amounts of resources.

In many scenarios, system administrators need to identify which processes are consuming the most memory to troubleshoot performance issues or optimize system resources. This requires sorting processes by their actual memory usage in descending order.

Using the ps Command

The most effective approach is to use the ps command with sorting options. The ps command (short for "process status") lists currently running processes along with detailed information about resource usage.

Basic ps Command

First, let's examine the basic ps command syntax −

ps [options]

To view all running processes −

ps aux
USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
root         1  0.0  0.1  20304  3896 ?        Ss   Jun25  19:53 /sbin/init
root        56  0.0  0.2  28476  8192 ?        S    Jun25   0:41 /usr/sbin/syslogd
root        57  0.0  0.3  32584 12288 ?        S    Jun25   0:59 /usr/libexec/UserEventAgent

Sorting by Memory Usage

To sort processes by memory usage in ascending order −

ps aux --sort=%mem

To sort in descending order (highest memory usage first) −

ps aux --sort=-%mem
USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
immukul   2386  3.6 16.0 1752740 605372 ?      Sl   10:30   2:15 /usr/bin/firefox
immukul   5142  0.1  6.3 2581944 239408 pts/0  Sl+  11:45   0:05 /usr/bin/chrome
immukul   5147  0.0  4.5  660556 170920 pts/0  S+   11:47   0:00 /usr/bin/code
immukul   5150  0.0  4.4  660620 168488 pts/0  S+   11:47   0:00 /usr/bin/gedit
immukul   2286  0.3  3.8 1316000 143312 ?      S    10:25   0:30 /usr/bin/gnome-shell
root      1284  1.5  3.7  452692 142796 tty7   Rs+  10:00   1:25 /usr/bin/Xorg

Limiting Output

To display only the top 10 memory-consuming processes −

ps aux --sort=-%mem | head -n 11

Using the top Command

The top command can also be configured to sort by memory usage. After launching top, press Shift + M to sort by memory usage interactively.

Alternatively, you can start top with memory sorting enabled −

top -o %MEM
PID    USER      PR  NI    VIRT    RES    SHR S  %CPU  %MEM     TIME+ COMMAND
2386   immukul   20   0 1752740 605372  85432 S   3.6  16.0   2:15.42 firefox
5142   immukul   20   0 2581944 239408  45672 S   0.1   6.3   0:05.21 chrome
5147   immukul   20   0  660556 170920  32144 S   0.0   4.5   0:00.85 code
5150   immukul   20   0  660620 168488  31208 S   0.0   4.4   0:00.92 gedit
2286   immukul   20   0 1316000 143312  28456 S   0.3   3.8   0:30.15 gnome-shell
1284   root      20   0  452692 142796  22184 S   1.5   3.7   1:25.33 Xorg

Key Memory Columns

Understanding the memory-related columns is crucial −

  • %MEM − Percentage of physical RAM used by the process

  • VSZ − Virtual memory size (total virtual memory used)

  • RSS − Resident Set Size (physical memory currently used)

Alternative Commands

For more advanced memory analysis −

# Show top 5 processes by RSS (actual memory usage)
ps aux --sort=-rss | head -n 6

# Combine with specific fields
ps -eo pid,ppid,cmd,%mem,%cpu --sort=-%mem | head -n 10

Conclusion

Sorting processes by memory usage is essential for system monitoring and troubleshooting. The ps aux --sort=-%mem command provides the most straightforward method to identify memory-intensive processes, while top -o %MEM offers real-time monitoring capabilities for dynamic system analysis.

Updated on: 2026-03-17T09:01:38+05:30

511 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements