How to Check Which Processes Are Using the Most Memory in Linux

When a physical Linux server in a data center suddenly becomes incredibly sluggish, unresponsive to SSH commands, or begins crashing web applications unexpectedly, the most common culprit is a specific background process (a daemon) suffering from a “memory leak.” This occurs when poorly written software aggressively consumes all of the server’s available RAM without ever giving it back. If you do not quickly identify and terminate the rogue process, the Linux kernel will inevitably panic and crash the entire machine to protect itself. To instantly view exactly which programs are hoarding your RAM, you can use the interactive top command combined with a highly specific sorting shortcut.

Launching the Interactive Task Manager

The top command is the terminal equivalent of the Windows Task Manager. It provides a constantly updating, real-time view of your system’s resources.

  1. Open your terminal application (or connect to your remote server via SSH).
  2. Type the following command and press Enter:
top

The terminal will instantly fill with a massive, rapidly changing block of text. The top few lines provide a summary of your total CPU and memory usage, while the table below lists every single active process currently running on the motherboard. By default, this list is usually sorted by CPU usage, which is not helpful when you are hunting for a memory leak.

Sorting by Maximum Memory Consumption

To instantly identify the culprit, you must force the table to re-sort itself based on RAM consumption.

  1. While the top command is running, simply press Shift + M (a capital M) on your keyboard.

The most memory-hungry programs will instantly jump to the absolute top of the list. Look at the column labeled %MEM. This shows exactly what percentage of your total physical RAM that specific program is currently eating. The column labeled RES (Resident Size) shows the exact amount of memory in kilobytes.

Once you have identified the rogue process (for example, a runaway Java application or a broken MySQL query), note the number in the far-left PID (Process ID) column. You can press Q to quit the top interface, and then forcefully terminate the broken software by typing sudo kill -9 [PID].

Get the best tech tips delivered straight to your inbox.

Join thousands of readers mastering Apple, Google, Microsoft, and Linux.