↑ ↓ select, Enter open, Esc close

Find out which processes are using swap

user@server
for f in /proc/[0-9]*/status; do awk '/^Name:/ {n=$2} /^VmSwap:/ {print $2, "kB", n}' "$f"; done 2>/dev/null | sort -rn | head -15

Reads the Name and VmSwap fields from /proc/<PID>/status for each process and sorts by the amount swapped out. free -h only shows that swap is in use; this command shows by whom. A lot of swapped memory for the database or php-fpm is a clear sign of too little RAM or overly generous limits.

Note: Used swap alone is not a problem, as long as vmstat 1 shows little ongoing swapping in the si and so columns.

Also searched as

  • what is using my swap
  • swap is full which process
  • swap usage per process
  • why is the server swapping

Related one-liners

All in Processes

Read first, then run.

The commands on myline.de act directly on servers, files and databases. A wrong path or placeholder can delete data irreversibly or make a server unreachable.

  • All commands are provided without warranty and are not tested on every system.
  • Understand what a command does before running it, and check every placeholder.
  • Make a backup first and, if possible, try it on a test system.
  • You run commands at your own risk. Liability for damages is excluded to the extent permitted by law.