目次

17 swapを食っているプロセスを調べる

CentOS 5系

#!/bin/bash
for i in `ls /proc/ | grep ^[0-9]`
do
  if [ -e /proc/$i/smaps ];then
    SWAP=`cat /proc/$i/smaps | awk 'BEGIN{sum=0} /^Swap/ {sum+=$2}END{print sum}'`
    if [ $SWAP -gt 0 ];then
      printf "$i\t$SWAP kb\t"
      ps -p $i -o cmd,user | grep -v 'CMD'
    fi
  fi
done

Cent 6系

#!/bin/bash
for i in `ls /proc/ | grep ^[0-9]`
do
  if [ -e /proc/$i/status ];then
    SWAP=`cat /proc/$i/status | awk 'BEGIN{sum=0} /^VmSwap/ {sum+=$2}END{print sum}'`
    if [ $SWAP -gt 0 ];then
      printf "$i\t$SWAP kb\t"
      ps -p $i -o cmd,user | grep -v 'CMD'
    fi
  fi
done