get_swap.sh
獲取當前佔用swap的pid
指令碼內容
#!/bin/bash
function getswap {
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"
}
getswap
執行指令碼
]$ sh getswap.sh |grep -v "Swap used: 0"
PID=1104 - Swap used: 644 - (xxx)
PID=1105 - Swap used: 384 - (xxx)
PID=27939 - Swap used: 56 - (xxx)
Overall swap used: 1084
指令碼內容
#!/bin/bash
function getswap {
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"
}
getswap
執行指令碼
]$ sh getswap.sh |grep -v "Swap used: 0"
PID=1104 - Swap used: 644 - (xxx)
PID=1105 - Swap used: 384 - (xxx)
PID=27939 - Swap used: 56 - (xxx)
Overall swap used: 1084
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/27000195/viewspace-2125665/,如需轉載,請註明出處,否則將追究法律責任。