Swap usage
August 07, 2024
Get a swap usage by pid/command:
ps -e -o pid,comm --no-headers | while read -r pid comm; do swap=$(grep Swap /proc/$pid/smaps 2>/dev/null | awk '{ sum += $2 } END { print sum }'); [ -n "$swap" ] && echo "PID: $pid - Swap used: ${swap:-0} kB - Command: $comm"; done | sort -k6 -nr
Using Top:
top -o SWAP -bn1 | head -n20