Last active
August 29, 2015 14:02
-
-
Save nkwhr/6c94a2397645abe9cf9b to your computer and use it in GitHub Desktop.
A shellscript to check who's hogging swap.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
## e.g.) sudo ./swap_stats.sh | column -t | sort -nrk3 | head -n25" | |
if [ $UID -ne 0 ] ; then | |
echo "You must be root to run this script." 1>&2 | |
exit 1 | |
fi | |
TOTAL_SWAP=0 | |
for PID in $(ls -1 /proc | grep ^[0-9]) ; do | |
PROG=$(ps -p $PID -o comm --no-heading) | |
SWAP=$(grep ^Swap /proc/$PID/smaps 2>/dev/null | awk 'BEGIN{SUM=0}{SUM+=$2}END{print SUM}') | |
if [ $SWAP -gt 0 ] ; then | |
echo "PID=$PID ($PROG) $SWAP KB" | |
TOTAL_SWAP=(expr $TOTAL_SWAP + $SWAP) | |
fi | |
done | |
echo "TOTAL --- $TOTAL_SWAP KB" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment