Skip to content

Instantly share code, notes, and snippets.

@tvlooy
Created July 15, 2015 12:00
Show Gist options
  • Select an option

  • Save tvlooy/7485a958fb73720f5035 to your computer and use it in GitHub Desktop.

Select an option

Save tvlooy/7485a958fb73720f5035 to your computer and use it in GitHub Desktop.
Find swap users
#!/bin/bash
TOTAL=0
for i in `find /proc -maxdepth 2 -type f -name status`; do
PID=`echo $i | cut -d/ -f3`
SWAP=$(grep VmSwap /proc/$PID/status 2>/dev/null | cut -d: -f2 | xargs | grep -v '^0 kB$')
if [ -n "$SWAP" ]; then
echo "$PID (`ps -p $PID -o comm=`) = $SWAP"
let TOTAL=$TOTAL+`echo $SWAP | cut -d' ' -f1`
fi
done
echo total $TOTAL kB
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment