linux下的小脚本

一、用于统计进程的swap使用情况

环境:LSB Version::core-4.0-amd64:core-4.0-ia32:core-4.0-noarch:graphics-4.0-amd64:graphics-4.0-ia32:graphics-4.0-noarch:printing-4.0-amd64:printing-4.0-ia32:printing-4.0-noarch

#!/bin/bash
#
function getswap {
SUM=0
OVERALL=0
for DIR in `find /proc/ -maxdepth 1 -type d | egrep "^/proc/[0-9]"` ; do
#get process swap infomation
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
#if process do not use swap. then ignore it
if ((SUM != 0)); then
echo "PID=$PID - Swap used: $SUM - ($PROGNAME )";
fi
let OVERALL=$OVERALL+$SUM
SUM=0
done
echo "Overall swap used: $OVERALL"
}
getswap

reference:http://freeloda.blog.51cto.com/2033581/1221653

 

posted @ 2014-05-26 16:10  惡盈好謙  阅读(160)  评论(0编辑  收藏  举报