whatswap - Find out what processes are using swap in Linux
Here’s a small bash script which will give you a breakdown on which processes are using swap in Linux
1 2 3 4 5 6 7 8 9 10 11 12 | #!/bin/bash LIMIT=${1:-30} printf "\e[1m\e[4m%-25s %-25s %s\e[0m\n" "PID" "Swap (kB)" "Process" echo -en " -=[ Doing the Needful once on priority ]=-\r" for x in $(grep Swap /proc/[1-9]\*/smaps 2>/dev/null | grep -v '\W0 kB' | tr -s ' ' | cut -d' ' -f-2 | sort -t' ' -k2 -n | tr -d ' ' | tail -$LIMIT); do SWAPUSAGE=$(echo $x | cut -d: -f3) PID=$(echo $x | cut -d/ -f3) PROCNAME=$(ps -p $PID -o args=) #$(grep -w $PID `ps ax | awk '{print $1 " " $5}'` | awk '{print $2}') printf "%-25s %-25s %s\n" $PID $SWAPUSAGE "$PROCNAME" done |