Linux下查看进程swap情况的脚本

1 #!/bin/bash
2 swapedall=0
3
4 pidarray=(`ls /proc/* |grep --color '[[:digit:]]' |grep proc |awk -F ":" '{print $1}'`)
5 arraylen=${#pidarray[*]}
6 for ((i=0;i<$arraylen;i=i+1))
7 do
8 if [ ! -d ${pidarray[$i]} ];then
9 continue
10 fi
11
12 pid=`echo "${pidarray[$i]}"|awk -F"/" '{print $3}'`
13 pidname=`cat ${pidarray[$i]}/status|grep Name|awk '{print $2}'`
14
15 swapedm=(`cat ${pidarray[$i]}/smaps|grep Swap|awk '{print $2}'`)
16
17 sum=0
18 for ((j=0;j<${#swapedm[*]};j++));do
19
20 if [ ${swapedm[$j]} ];then
21 let sum+=${swapedm[$j]}
22 fi
23 done
24 if [ $sum -eq 0 ];then
25 continue
26 fi
27 if [ $swapedm ];then
28 let swapedall+=$sum
29 echo 'process is :' $pidname',' 'pid is:' $pid',' 'swaped:' $sum 'KB'
30 fi
31
32 done
33
34 echo 'total swaped:' $swapedall 'KB'

posted @ 2017-02-15 17:23  XavierLee  阅读(390)  评论(0编辑  收藏  举报