aboutsummaryrefslogtreecommitdiff
path: root/bin/swaptop
blob: b11fd92379798d057dd0084c5f5f271e3f7c40c8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#!/bin/sh
# swaptop - show most swap-using processes
# 17sep2011  +chris+, portable 19sep2011  +chris+

if grep -q VmSwap /proc/1/status; then
    # Efficient interface since revision b084d435.
    awk '/^Name:/ { name = $2 }
         /^Pid:/ { pid = $2}
         /^VmSwap:/ {
             swap = $2
             if (swap>0)
                 printf "%8d  %s %d\n", swap, name, pid
         }' /proc/[0-9]*/status | sort -nr
else
    for f in /proc/[0-9]*; do
    # awk will fail on permission denied
        awk 'BEGIN { swap=0 }
             $30 { pid = $1; name = substr($2,2,length($2)-2) }
             $1=="Swap:" {swap += $2}
             END { if (swap>0) printf "%8d  %s %d\n", swap, name, pid }' \
            $f/stat $f/smaps 2>/dev/null
    done | sort -nr 
fi