Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
portable swaptop
  • Loading branch information
leahneukirchen committed Sep 19, 2011
1 parent a8a20d0 commit b16ef5a
Showing 1 changed file with 20 additions and 8 deletions.
28 changes: 20 additions & 8 deletions swaptop
@@ -1,11 +1,23 @@
#!/bin/sh
# swaptop - show most swap-using processes
# 17sep2011 +chris+
# 17sep2011 +chris+, portable 19sep2011 +chris+

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
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

0 comments on commit b16ef5a

Please sign in to comment.