Skip to content

Instantly share code, notes, and snippets.

@marksteward
Created April 4, 2014 22:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save marksteward/9984603 to your computer and use it in GitHub Desktop.
Save marksteward/9984603 to your computer and use it in GitHub Desktop.
#!/bin/bash
output=$(
for pid in `ls /proc|grep '^[0-9]\+$'`; do
if [[ -f /proc/$pid/smaps ]]; then
if cat /proc/$pid/smaps >/dev/null; then
swap=`grep Swap /proc/$pid/smaps | awk 'BEGIN {s = 0} {s += $2} END {print s}'`
proc=`ps -p $pid -o cmd --no-headers`
echo "$swap kB PID $pid ($proc)"
fi
fi
done
)
echo "$output"|sort -n
echo Total: `echo "$output" | awk 'BEGIN {t = 0} {t += $1} END {print t}'` kB
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment