-
Notifications
You must be signed in to change notification settings - Fork 2
/
swaptop
executable file
·46 lines (44 loc) · 1019 Bytes
/
swaptop
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#!/bin/sh
#
# Display most swap-using processes.
#
# Source: http://chneukirchen.org/dotfiles/bin/swaptop
if command -- grep -q -F VmSwap /proc/1/status; then
exec mawk '
/^Name:/ {
name = $2
};
/^Pid:/ {
pid = $2
};
/^VmSwap:/ {
swap = $2
if (swap > 0) {
printf "%8d %s %d\n", swap, name, pid
}
}
' /proc/[0-9]*/status |
exec sort -r
else
for f in /proc/[0-9]*; do
command -- mawk '
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 |
exec sort -r
fi
# vim: set ft=sh :