Skip to content

Instantly share code, notes, and snippets.

@inetfuture
Created May 16, 2013 01:03
Show Gist options
  • Save inetfuture/5588677 to your computer and use it in GitHub Desktop.
Save inetfuture/5588677 to your computer and use it in GitHub Desktop.
#! /bin/bash
cd /proc
for pid in [0-9]*; do
command=$(cat /proc/$pid/cmdline)
swap=$(
awk '
BEGIN { total = 0 }
/Swap/ { total += $2 }
END { print total }
' /proc/$pid/smaps
)
if (( $swap > 0 )); then
if [[ "${head}" != "yes" ]]; then
echo -e "PID\tSWAP\tCOMMAND"
head="yes"
fi
echo -e "${pid}\t${swap}\t${command}"
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment