Skip to content

How to List Processes by Memory Usage in Linux (Top 10 RAM Users)

Find the processes using the most memory in Linux with ps, top, htop, systemd-cgtop and smem: top 10 by RAM, totals per program and service, swap users, OOM kills, and how to fix a memory hog.

Category
Linux
On this page

When a Linux server slows down, starts swapping or has processes killed by the kernel, the first question is simple: which processes are using the most memory? Linux can answer that with tools you already have, mainly ps and top. This guide shows how to list processes by memory usage, find the top 10 RAM users, read the numbers correctly, and fix the process once you’ve found it.

The quick answer is this command, which lists the 10 processes using the most memory:

ps -eo pid,user,%mem,rss,comm --sort=-rss | head -n 11

head -n 11 prints the header line plus 10 processes. Change it to head -n 21 for the top 20.

Method 1: List Processes by Memory with ps

ps takes a one-time snapshot, which makes it the best tool for scripts, logs and quick checks over SSH. Use -o to choose the columns and --sort=-rss to sort by resident memory, largest first (the minus sign means descending):

ps -eo pid,user,%mem,rss,comm --sort=-rss | head -n 11

Example output from an Ubuntu server:

    PID USER     %MEM   RSS COMMAND
    846 root     19.8 1612220 dockerd
3444189 mysql     9.7 789392 mysqld
3489172 ubuntu    5.1 419164 next-server
...

The columns mean:

  • PID: the process ID, which you need to inspect or stop the process.
  • USER: the account the process runs as.
  • %MEM: the share of total physical RAM the process uses.
  • RSS: resident set size, the physical RAM the process uses right now, in kilobytes.
  • COMMAND: the program name. Use cmd instead of comm to see the full command line with its arguments.
ps command listing the top 10 memory consuming processes in Linux
Top 10 memory-consuming processes listed with ps

Show memory in MB instead of KB

RSS in kilobytes is hard to read. Pipe the output through awk to convert it to megabytes:

ps -eo pid,user,rss,comm --sort=-rss | awk 'NR==1{printf "%-8s %-10s %10s %s\n","PID","USER","MEM","COMMAND";next} NR<=11{printf "%-8s %-10s %7.1f MB %s\n",$1,$2,$3/1024,$4}'
PID      USER              MEM COMMAND
846      root         1574.4 MB dockerd
3444189  mysql         770.9 MB mysqld
3489172  ubuntu        409.3 MB next-server

Total memory per program

Programs such as PHP-FPM, Apache, Chrome and PostgreSQL run many processes, and each one can look small on its own. To add up the memory of every process with the same name:

ps -eo rss,comm --no-headers | awk '{m[$2]+=$1} END{for(p in m) printf "%10.1f MB  %s\n", m[p]/1024, p}' | sort -rn | head -n 10
    1574.4 MB  dockerd
    1035.3 MB  php-fpm8.4
     770.9 MB  mysqld
     694.7 MB  next-server

Here php-fpm8.4 didn't appear in the per-process list at all, but its worker pool is the second-largest user of RAM on the server. Shared memory is counted once for each worker in this sum, so treat it as an upper bound (see RSS vs PSS below).

Method 2: Sort Processes by Memory in top

top shows the same information live, refreshing every few seconds. Start it and press Shift + M to sort by memory:

top

The process using the most memory moves to the top of the list, sorted by the %MEM column. Press Shift + P to go back to sorting by CPU, e to switch memory units (KiB, MiB, GiB) in the process list, and q to quit. You can also start top already sorted by memory:

top -o %MEM
top command sorting Linux processes by memory usage
top sorted by the %MEM column

For a one-off snapshot you can save or paste into a ticket, run top in batch mode for a single update:

top -b -n 1 -o %MEM | head -n 17

The first 7 lines are the summary and the column header, so 17 lines give you the top 10 processes. In top, RES is the same as RSS in ps, and VIRT is virtual memory, which is usually much larger than the RAM actually in use. Ignore VIRT when you're looking for memory hogs. Our top command guide explains every column.

Method 3: Use htop

htop is an easier, colour version of top that you can scroll with the mouse. Install it if it's missing:

sudo apt install htop

On RHEL, Rocky Linux, AlmaLinux and Fedora, use sudo dnf install htop. Start htop and press Shift + M to sort by memory, or press F6 and choose PERCENT_MEM. Press F5 for a tree view that groups child processes under their parent, which helps with services that start many workers. More shortcuts are in our htop command guide.

Method 4: Memory Usage per systemd Service

On servers, it's often more useful to know which service uses the most memory than which single process. systemd-cgtop adds up every process in each service's control group, including all its workers:

systemd-cgtop -m

The -m option sorts by memory. Press q to quit. For a single snapshot, add -b -n 1:

systemd-cgtop -m -b -n 1 --depth=2 | head -n 12
system.slice                         482      -     5.1G        -        -
system.slice/docker.service           93      -     1.6G        -        -
system.slice/mysql.service            47      -   932.4M        -        -
user.slice                            28      -   740.5M        -        -

To check one service, systemctl status mysql shows a Memory: line, and systemctl show mysql -p MemoryCurrent prints the exact number of bytes. For containers, docker stats --no-stream shows memory per container.

RSS vs PSS: Read the Numbers Correctly

RSS counts every page a process has in RAM, including shared libraries and shared memory that other processes use too. If 20 PHP-FPM workers share 30 MB of code, each worker's RSS includes those 30 MB, so adding up their RSS overstates the real total. That's why the sum of RSS across all processes can be larger than the RAM in the machine.

PSS (proportional set size) fixes this by splitting each shared page between the processes that share it. The smem tool reports PSS:

sudo apt install smem
sudo smem -k -r -s pss | head -n 11

-s pss sorts by PSS, -r puts the largest first, and -k shows sizes in MB and GB. The USS column shows memory used only by that process: roughly what you'd get back if you stopped it.

For one process, /proc shows how its resident memory is made up:

grep -E 'VmRSS|RssAnon|RssFile|RssShmem|VmSwap' /proc/1234/status

Replace 1234 with the PID. RssAnon is the process's own heap and stack, the part that grows with a memory leak. RssFile is mapped files and libraries, and VmSwap is how much of the process has been moved to swap. pmap -x 1234 breaks the memory down by mapping.

Find Which Processes Are Using Swap

When free -h shows swap in use, the processes that own it don't always show up in the RSS list, because swapped-out memory isn't resident. This loop reads VmSwap for every process:

for f in /proc/[0-9]*/status; do awk '/^Name/{n=$2} /^Pid/{p=$2} /^VmSwap/{if($2>0) printf "%8.1f MB  %-8s %s\n",$2/1024,p,n}' "$f" 2>/dev/null; done | sort -rn | head -n 10
   520.4 MB  846      dockerd
   287.4 MB  3444189  mysqld
    74.5 MB  3444010  redis-server

Run it with sudo to include every user's processes.

Check Whether the OOM Killer Has Stepped In

When Linux runs out of memory and swap, the kernel's OOM killer stops a process to free RAM, usually the largest one. If a database or web server disappeared without a clean shutdown, check the kernel log:

sudo journalctl -k | grep -i -E "out of memory|oom-kill"

On systems without the journal, use sudo dmesg -T | grep -i oom. Each entry names the process that was killed and how much memory it held.

What to Do About a Memory-Hungry Process

Finding the process is half the job. A large number is not always a problem: databases such as MySQL and PostgreSQL deliberately use RAM for caching, and Linux uses spare RAM as file cache. Check the available column of free -h first. If it's healthy, the system isn't short of memory. If it's low, here's what to do:

1. Restart or stop the process cleanly

A process with a memory leak only gets bigger over time. For a service, restart it so it starts fresh:

sudo systemctl restart php8.4-fpm

For a stray process you don't need, send the normal termination signal first, which lets it clean up:

kill 1234

Use kill -9 1234 only if the process ignores that. See how to kill a process by ID for more options.

2. Tune the application's memory settings

Most large memory users have a setting that controls how much RAM they take: innodb_buffer_pool_size in MySQL, shared_buffers in PostgreSQL, pm.max_children in PHP-FPM, maxmemory in Redis, and -Xmx for Java. Sizing these for the server is usually the real fix. For PHP, see how to reduce PHP-FPM memory usage; for Redis, how to set Redis max memory.

3. Put a hard limit on a service

systemd can cap how much memory a service may use, so one runaway service can't take down the whole server. Run sudo systemctl edit myapp and add:

[Service]
MemoryHigh=1G
MemoryMax=1.5G

Then restart the service. Above MemoryHigh the kernel slows the service down and reclaims its memory hard; at MemoryMax the OOM killer stops it inside its own group, leaving the rest of the system alone. Docker containers take the same kind of limit with --memory; see CPU and memory limits in Docker.

4. Add swap as a safety net

Swap doesn't make a server faster, but it gives the kernel somewhere to move idle memory instead of killing processes. A server with no swap at all hits the OOM killer sooner. To add a 2 GB swap file:

sudo fallocate -l 2G /swapfile
sudo chmod 600 /swapfile
sudo mkswap /swapfile
sudo swapon /swapfile

Add /swapfile none swap sw 0 0 to /etc/fstab to keep it after a reboot. The full steps are in how to add swap on Ubuntu 24.04, and you can control how eagerly Linux uses it with the swappiness value.

Note: nice and renice change a process's CPU priority only. They don't reduce how much memory it uses, so they won't help with a memory problem.

Log the Top Memory Users Over Time

Memory problems often happen at night or under load, when no one is watching. A cron job can save a snapshot every 5 minutes so you can see later which process grew. Open root's crontab with sudo crontab -e and add:

*/5 * * * * (date; ps -eo pid,user,%mem,rss,comm --sort=-rss | head -n 11) >> /var/log/top-memory.log

The log grows by about 1 KB per run, so remove it or set up log rotation once you've found the cause. For permanent monitoring on production servers, use a monitoring system such as Prometheus with node_exporter, Netdata or Zabbix.

Quick Reference

TaskCommand
Top 10 processes by memoryps -eo pid,user,%mem,rss,comm --sort=-rss | head -n 11
Same, with full command lineps -eo pid,user,%mem,rss,cmd --sort=-rss | head -n 11
Live view sorted by memorytop -o %MEM (or press Shift + M in top or htop)
One-time top snapshottop -b -n 1 -o %MEM | head -n 17
Memory per servicesystemd-cgtop -m
Memory with shared pages split fairlysudo smem -k -r -s pss
Memory of one processgrep -E 'VmRSS|VmSwap' /proc/PID/status
Overall RAM and swapfree -h
Processes killed for lack of memorysudo journalctl -k | grep -i oom

Frequently Asked Questions

How do I list processes by memory usage in Linux?

Run ps -eo pid,user,%mem,rss,comm --sort=-rss | head -n 11. It sorts every process by resident memory, largest first, and shows the top 10. In top or htop, press Shift + M instead.

Which process is using the most memory?

It's the first line of the ps ... --sort=-rss output, or the top of top after you press Shift + M. For services with many workers, also check systemd-cgtop -m, because the total for a service can be larger than any single process.

What is the difference between RSS and %MEM?

RSS is the physical memory a process uses, in kilobytes. %MEM is the same amount shown as a percentage of the machine's total RAM. Sorting by either gives the same order.

Why don't the process totals add up to the "used" value in free?

RSS counts shared libraries and shared memory in every process that uses them, so the sum is too high. free also counts the kernel's own memory, which doesn't belong to any process. Use smem and its PSS column for a fairer total.

Why is VIRT so much bigger than RES in top?

VIRT is all the address space a process has reserved, including memory it never uses and files it has mapped. RES (RSS) is what is actually in RAM. Use RES or %MEM to find memory hogs.

Does killing a process free its memory immediately?

Yes. When a process exits, the kernel frees its private memory straight away. Shared memory is freed when the last process using it exits.

Conclusion

To find the processes using the most memory in Linux, start with ps -eo pid,user,%mem,rss,comm --sort=-rss | head -n 11 for a quick list, or top and htop with Shift + M for a live view. For services with many workers, add up memory per program or use systemd-cgtop -m, and use smem when shared memory makes the RSS numbers misleading. Once you've found the process, restart it, tune its memory settings or cap it with systemd instead of reaching for kill -9. To check CPU and memory together in one pass, see how to find the top CPU and memory consuming processes in Linux.

Rahul

Rahul Kumar is the founder and chief editor of TecAdmin.net. A Red Hat Certified Engineer (RHCE), he has worked in IT since 2009, with hands-on experience in Linux system administration, DevOps, web hosting, cloud platforms and automation. He started TecAdmin in 2013 to share practical, step-by-step guides, and leads its editorial work with one aim: making technical learning clear and useful for sysadmins, developers and beginners alike.

Leave a Reply

Your email address will not be published. Required fields are marked *


Back to top