Ajout : local/swap : calcule préçisément l'utilisation du swap de chaque processus.
authorJulien Moutinho <julm+heureux-cyclage@autogeree.net>
Tue, 24 Sep 2013 22:20:38 +0000 (00:20 +0200)
committerJulien Moutinho <julm+heureux-cyclage@autogeree.net>
Tue, 24 Sep 2013 22:31:18 +0000 (00:31 +0200)
local/swap [new file with mode: 0755]

diff --git a/local/swap b/local/swap
new file mode 100755 (executable)
index 0000000..50f85cf
--- /dev/null
@@ -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' ' ' </proc/"$lastpid"/cmdline)"
+                fi
+               if test "$pid" = self
+                then break
+                else
+                       lastpid=$pid
+                       swap=$size
+                fi
+        fi
+ done |
+sort -nk1,1