List processes currently using swap space (BASH)

When trying to work out where all your RAM went, it's sometimes useful to be able to take a look at what currently has pages in swap.

It's worth bearing in mind, though, that processes listed aren't necessarily the root cause - they may well have been paged out to free up RAM for some other process

Details

  • Language: BASH

Snippet

for file in /proc/*/status ; do awk '/Name|VmSwap/{printf $2 " " $3}END{ print ""}' $file; done | sort -k 2 -n -r