X-Git-Url: https://git.cyclocoop.org/?a=blobdiff_plain;ds=sidebyside;f=local%2Fswap;fp=local%2Fswap;h=50f85cf98aa0acfe33aa37d8683c997dcb1af792;hb=865d9029c1113acde6b5c300c75f727fa68cdfea;hp=0000000000000000000000000000000000000000;hpb=7ec5ddab73855d65555a21873ccf8d2653a22ee6;p=lhc%2Fateliers.git diff --git a/local/swap b/local/swap new file mode 100755 index 0000000..50f85cf --- /dev/null +++ b/local/swap @@ -0,0 +1,28 @@ +#!/bin/sh -eu +# SYNTAX: +# DESCRIPTION: print sorted swap usage of processes using it + +lastpid= +swap=0 +sudo grep -H '^Swap:' /proc/*/smaps 2>/dev/null | +while IFS=: read -r file x size x + do + pid=${file#/proc/} + pid=${pid%/smaps} + size=${size% kB} + size=${size##* } + if test "$pid" = "$lastpid" + then swap=$(( swap + size )) + else + if test "$swap" -gt 0 + then printf "%u pid=%u cmd=%s\n" "$swap" "$lastpid" "$(tr '\000' ' '