Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
portable swaptop
- Loading branch information
1 parent
a8a20d0
commit b16ef5a
Showing
1 changed file
with
20 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |