#!/usr/bin/sh
#
# Get current swap usage for all running processes

for dir in $(find /proc/ -maxdepth 1 -type d |grep -E "[0-9]+"); do
  pid=$(echo $dir |cut -d/ -f3)
  cmd=$(ps h -o comm -p $pid)
  swap=$(grep VmSwap $dir/status 2> /dev/null |awk '{print $2}')
  if [ ! -z $swap ]; then
     echo "pid: $pid command: $cmd - SwapUsed: $swap KB"
  fi
done |sort -nk5 |column -t
