美文网首页
6 Linux查看整个系统的swap占用代码

6 Linux查看整个系统的swap占用代码

作者: Guoyubo | 来源:发表于2019-08-05 13:44 被阅读0次
#!/bin/bash
# Get current swap usage for all running processes
# Erik Ljungstrom 27/05/2011
do_swap () {
SUM=0
OVERALL=0
for DIR in `find /proc/ -maxdepth 1 -type d | egrep "^/proc/[0-9]"` ; do
PID=`echo $DIR | cut -d / -f 3`
PROGNAME=`ps -p $PID -o comm --no-headers`
for SWAP in `grep Swap $DIR/smaps 2>/dev/null| awk '{ print $2 }'`
do
let SUM=$SUM+$SWAP
done
echo "PID=$PID - Swap used: $SUM - ($PROGNAME )"
let OVERALL=$OVERALL+$SUM
SUM=0
 
done
echo "Overall swap used: $OVERALL"
}
do_swap  |awk -F[\ \(] '{print $5,$1,$8}' | sort -n | tail -3
 

相关文章

网友评论

      本文标题:6 Linux查看整个系统的swap占用代码

      本文链接:https://www.haomeiwen.com/subject/ggfmdctx.html