There's already a good answer to the question at
stackoverflow. They suggested to use the
top command, then change the sorting field to "swap" by hitting
O and
p. Unfortunately (afaik) there's no way to do this in batch mode (using the
-b switch) and save the top swap using prorcesses in a file. There's another method: use the
ps command.
psres=$(ps -eo rss,vsz,user,pid,tty,time,cmd); set -- $(/bin/echo "$psres" | head -n1); shift; shift; echo "SWAP $*"; echo "$psres" | awk 'BEGIN {ORS=""; getline} {print $2 - $1 " "; for (i=3; i<NF; i++) print $i " "; print $NF "\n"}' | sort -rn | head
Recent comments
1 day 13 hours ago
1 day 18 hours ago
3 days 1 hour ago
3 days 5 hours ago
3 days 10 hours ago
5 days 7 hours ago
1 week 8 hours ago
1 week 2 days ago
1 week 5 days ago
1 week 6 days ago