Find out which processes are Swapping
From Zarafa wiki
(Difference between revisions)
(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...") |
|||
| (One intermediate revision not shown) | |||
| Line 1: | Line 1: | ||
| - | 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. | + | 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 and must be run by root. |
| Line 9: | Line 9: | ||
SUM=0 | SUM=0 | ||
OVERALL=0 | OVERALL=0 | ||
| + | |||
| + | if [ "$(id -u)" != "0" ]; then | ||
| + | echo "This script must be run as root" 1>&2 | ||
| + | exit 1 | ||
| + | fi | ||
for DIR in `find /proc/ -maxdepth 1 -type d | egrep "^/proc/[0-9]"` ; do | for DIR in `find /proc/ -maxdepth 1 -type d | egrep "^/proc/[0-9]"` ; do | ||
| Line 23: | Line 28: | ||
echo "Overall swap used: $OVERALL" | echo "Overall swap used: $OVERALL" | ||
</pre> | </pre> | ||
| + | |||
| + | [[Category:Debug]] | ||
Latest revision as of 12:19, 2 January 2013
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 and must be run by root.
The script:
#!/bin/bash
#
SUM=0
OVERALL=0
if [ "$(id -u)" != "0" ]; then
echo "This script must be run as root" 1>&2
exit 1
fi
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"