swap.sh 470 B

1234567891011121314151617
  1. #!/bin/bash
  2. # Get current swap usage for all running processes
  3. # Erik Ljungstrom 27/05/2011
  4. SUM=0
  5. OVERALL=0
  6. for DIR in `find /proc/ -maxdepth 1 -type d | egrep "^/proc/[0-9]"` ; do
  7. PID=`echo $DIR | cut -d / -f 3`
  8. PROGNAME=`ps -p $PID -o comm --no-headers`
  9. for SWAP in `grep Swap $DIR/smaps 2>/dev/null| awk '{ print $2 }'`
  10. do
  11. let SUM=$SUM+$SWAP
  12. done
  13. echo "PID=$PID - Swap used: $SUM - ($PROGNAME )"
  14. let OVERALL=$OVERALL+$SUM
  15. SUM=0
  16. done
  17. echo "Overall swap used: $OVERALL"