Archives par mot-clé : Swap usage

Swap Usage par Processus

#!/bin/bash

# @DESCRIPTION: Get relevent processes swap usage by scanning all running processes
# @DATE: 26/08/2015

cat << EOF
============================================================
===== > Showing all *relevant* processes swap usage < ======
============================================================
EOF

for DIR in `find /proc/ -maxdepth 1 -type d | grep -E "^/proc/[0-9]"`
do
    [ "$OVERALL" == "" ] && OVERALL=0
    SUM=0
    PID=`echo $DIR | grep -Eo "[0-9]+$"`
    PROGNAME=`cat $DIR/comm 2>/dev/null || echo 'vanished process'`

    for SWAP in `grep Swap $DIR/smaps 2>/dev/null| awk '{ print $2 }'`
    do
        SUM=$(($SUM+$SWAP))
    done

    OVERALL=$(($OVERALL+$SUM))

    printf "%-20s : %-40s\n" "$(($SUM/1024)) MB" "$PROGNAME (PID $PID)"
    echo $OVERALL > /tmp/OVERALL
done | grep -vE "^0" | sort -n

cat << EOF

NOTICE : processes consuming less than 1MB are not shown
Total running processes swap usage: $((`cat /tmp/OVERALL`/1024)) MB
EOF

rm -f /tmp/OVERALL