Checking swap usage for each process in Linux

Moderator: cah

Post Reply
cah
General of the Army / Fleet Admiral / General of the Air Force
General of the Army / Fleet Admiral / General of the Air Force
Posts: 1336
Joined: Sun Aug 17, 2008 5:05 am

Checking swap usage for each process in Linux

Post by cah »

RHEL 6

Become root

Code: Select all

cd /proc
for i in *
do
  if [[ $i =~ ^[0-9]+$ ]]
  then
    SWAP=`pmap -x $i | grep ^total | awk '{ print $3; }'`
    [ "xx$SWAP" != "xx" ] && echo "$SWAP kB for PID $i"
  fi
done | sort -n | tail -20

RHEL 7

Become root

Code: Select all

cd /proc

for i in *
do
if [[ "$i" =~ ^[0-9]+$ ]]
then
  SWAP=`pmap $i | grep total | awk '{ print $2}'`
  if [[ "$SWAP" != "" ]]
  then
    Size=`echo $SWAP | cut -dK -f1`
    if [[ "$SWAP" != "0K" ]]
    then
      echo "$Size KB memory used by PID $i"
    fi
  fi
fi
done | sort -n

Code: Select all

cd /proc

for i in *
do
if [[ "$i" =~ ^[0-9]+$ ]]
then
  SWAP=`grep VmSwap $i/status | awk '{print $2}'`
  if [[ "$SWAP" != "0" ]]
  then
    if [[ "$SWAP" != "" ]]
    then
      echo "$SWAP KB swap used by PID $i"
    fi
  fi
fi
done | sort -n
CAH, The Great
Post Reply