内存检查 - 系统swap内存查看

优质
小牛编辑
132浏览
2023-12-01
  1. #!/bin/bash
  2. # Get current swap usage for all running processes
  3. # Erik Ljungstrom 27/05/2011
  4. # Modified by Mikko Rantalainen 2012-08-09
  5. # Pipe the output to "sort -nk3" to get sorted output
  6. # Modified by Marc Methot 2014-09-18
  7. # removed the need for sudo
  8. SUM=0
  9. OVERALL=0
  10. for DIR in `find /proc/ -maxdepth 1 -type d -regex "^/proc/[0-9]+"`
  11. do
  12. PID=`echo $DIR | cut -d / -f 3`
  13. PROGNAME=`ps -p $PID -o comm --no-headers`
  14. for SWAP in `grep VmSwap $DIR/status 2>/dev/null | awk '{ print $2 }'`
  15. do
  16. let SUM=$SUM+$SWAP
  17. done
  18. if (( $SUM > 0 )); then
  19. echo "PID=$PID swapped $SUM KB ($PROGNAME)"
  20. fi
  21. let OVERALL=$OVERALL+$SUM
  22. SUM=0
  23. done
  24. echo "Overall swap used: $OVERALL KB"