Quick Linux Tip #87:
Question: My server is swapping. Which processes are the culprits?
Try: for pid in $(ls /proc/ | grep -E '^[0-9]+$'); do awk -v pid=$pid '/VmSwap/ {print pid, $2, $3}' /proc/$pid/status 2>/dev/null; done | sort -k2 -rn | head -10
Info: /proc/PID/status tracks per-process VmSwap usage. Iterating through numeric PIDs extracts and ranks memory-heavy processes pushed into swap space.
Examples:
- $
sudo smem -tk -s swap# Display total proportional swap consumption per process - $
grep VmSwap /proc/*/status | sort -k2 -rn | head# Simple multi-proc status search - $
swapon --show# List active swap devices, types, and total usage
Note: Persistent heavy swapping indicates memory exhaustion or leaks. Install smem for accurate proportional swap accounting, or tune swap behavior via sysctl vm.swappiness=10.
Leave a Reply