Find out which processes are Swapping

From Zarafa wiki

(Difference between revisions)
Jump to: navigation, search
(Created page with "Ever wanted to know which processes are swapping and how much swap space they are using. Starting from kernel 2.6.16, we can find out using smaps which can be found in the proc f...")
Line 23: Line 23:
echo "Overall swap used: $OVERALL"
echo "Overall swap used: $OVERALL"
</pre>
</pre>
 +
 +
[[Category:Debug]]

Revision as of 07:08, 23 September 2011

Ever wanted to know which processes are swapping and how much swap space they are using. Starting from kernel 2.6.16, we can find out using smaps which can be found in the proc filesystem. The script below will make it easy for you and lists all processes and how much swap space they are using.


The script:

#!/bin/bash
#

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}K - ($PROGNAME )"
  let OVERALL=$OVERALL+$SUM
  SUM=0
done

echo "Overall swap used: $OVERALL"
Personal tools