What process is using how much swap memory

I found this interesting script that prints out a list of processes that are using swap space. I changed the output to suppress the PIDs that aren’t using swap.

# Get current swap usage for all running processes
# Erik Ljungstrom 27/05/2011
# Updated: 2013-11-13 Yuichiro Saito
# Updated: 2014-08-04 Juergen Caris
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 }'`
                let SUM=$SUM+$SWAP
        if [ $SUM -gt 0 ]
                echo "PID=$PID - Swap used: $SUM - (${PROGNAME})"
                let OVERALL=$OVERALL+$SUM
echo "Overall swap used: $OVERALL"

About Juergen Caris

I am 54yo, MSc(Dist) and BSc in Computer Science, German and working as a Senior Server Engineer for the NHS Lothian. I am responsible for the patient management system, called TrakCare. I am a UNIX/Linux guy, working in this sector for more than 20 years now. I am also interested in robotics, microprocessors, system monitoring, Home automation and programming.
This entry was posted in Bash, Hardware, Linux, Uncategorized. Bookmark the permalink.

Leave a Reply

Your email address will not be published.