Commands.page Logo

How to Filter Processes by RAM Usage in Ubuntu Linux

This guide explains how to identify and filter running processes on Ubuntu that exceed a specific memory threshold. You will learn command-line methods using standard tools like ps and awk to pinpoint high RAM usage quickly. These techniques help system administrators monitor performance and troubleshoot memory leaks efficiently without needing graphical interfaces.

Using PS and AWK

The most effective way to filter processes by a specific RAM amount is combining the ps command with awk. The ps aux command lists all running processes, where the fourth column represents memory usage as a percentage.

To list processes using more than 5% of your total RAM, run:

ps aux --sort=-%mem | awk 'NR==1 || $4 > 5.0'

This command sorts processes by memory usage descending and prints the header line plus any process where the memory column exceeds 5.0. You can change 5.0 to any threshold value you require.

Filtering by Kilobytes

If you prefer filtering by actual memory size rather than percentage, use the rss (Resident Set Size) parameter. The following command displays processes using more than 100,000 KB of RAM:

ps -eo pid,comm,rss --sort=-rss | awk 'NR==1 || $3 > 100000'

Here, $3 corresponds to the RSS column in kilobytes. Adjust the number to match your specific memory constraints.

Using Htop for Interactive Filtering

For a visual approach, install htop if it is not already available. Once launched, you can sort processes by memory by pressing F6 and selecting PERCENT_MEM or RESIDENT. While htop does not support numeric threshold filtering directly in the search bar, sorting allows you to visually identify top consumers immediately.

sudo apt install htop
htop

These methods provide immediate insight into memory consumption, allowing you to take action on resource-heavy processes.