You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
61 lines
1.5 KiB
61 lines
1.5 KiB
# --- enable/disable this file ---
|
|
SRC_ENABLED=true
|
|
|
|
case "$SRC_ENABLED" in
|
|
1|true|yes|on) unset SRC_ENABLED ;; # enabled — clean up and continue
|
|
*) unset SRC_ENABLED; return ;; # disabled — clean up and skip this file
|
|
esac
|
|
# ---------------------------------
|
|
|
|
swaptop()
|
|
{
|
|
local limit="${1:-10}"
|
|
local width="${2:-200}"
|
|
local p pid swap cmd
|
|
|
|
{
|
|
for p in /proc/[0-9]*; do
|
|
[ -r "$p/smaps" ] || continue
|
|
|
|
pid="${p##*/}"
|
|
|
|
swap=$(awk '
|
|
/^Swap:/ { swap += $2 }
|
|
/^SwapPss:/ { pss += $2; have_pss = 1 }
|
|
END {
|
|
if (have_pss)
|
|
print pss
|
|
else
|
|
print swap
|
|
}
|
|
' "$p/smaps" 2>/dev/null)
|
|
|
|
[ "${swap:-0}" -gt 0 ] || continue
|
|
|
|
cmd=$(tr '\0\t\n' ' ' < "$p/cmdline" 2>/dev/null)
|
|
|
|
if [ -z "$cmd" ]; then
|
|
cmd="[$(cat "$p/comm" 2>/dev/null)]"
|
|
fi
|
|
|
|
printf '%d\t%s\t%s\n' "$swap" "$pid" "$cmd"
|
|
done
|
|
} |
|
|
sort -nr -k1,1 |
|
|
head -n "$limit" |
|
|
awk -F '\t' -v width="$width" '
|
|
BEGIN {
|
|
printf "%10s %7s %s\n", "SWAP", "PID", "COMMAND"
|
|
printf "%10s %7s %s\n", "----------", "-------", "-------"
|
|
}
|
|
{
|
|
line = sprintf("%9.1fM %7s %s", $1 / 1024, $2, $3)
|
|
|
|
if (length(line) > width)
|
|
line = substr(line, 1, width - 3) "..."
|
|
|
|
print line
|
|
}
|
|
'
|
|
}
|