-
-
Save aramisf/c4fc8be6691826dfc6cf to your computer and use it in GitHub Desktop.
This file contains 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/bash | |
# Get current swap usage for all running processes | |
# Erik Ljungstrom 27/05/2011 | |
# | |
## Adapted by Jhonatan Piffer Siqueira and Eduardo Lemons Francisco (eddy85br). | |
OVERALL=0 | |
PROGLIST=$(ps axw -o pid,args --no-headers) | |
while read PID ARGS; do | |
SUM=0 | |
if [ -f "/proc/$PID/smaps" ]; then | |
for SWAP in $(fgrep 'Swap' /proc/$PID/smaps 2>/dev/null | awk '{ print $2 }') ; do | |
let SUM=$SUM+$SWAP | |
done | |
fi | |
if [[ $SUM > 0 ]]; then | |
printf "PID: %-6s | Swap used: %-6s KB => %s\n" $PID $SUM "$ARGS" | |
else | |
printf "Not using Swap, PID: %-6s => %s\n" $PID "$ARGS" 1>/dev/stderr | |
fi | |
let OVERALL=$OVERALL+$SUM | |
done <<<"$PROGLIST" | |
echo "Overall swap used: $OVERALL" | |
exit 0; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment