Skip to content

Instantly share code, notes, and snippets.

@gfldex
Last active October 6, 2016 23:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gfldex/2b43a001e6d5e6c0f03c0c3c3a837385 to your computer and use it in GitHub Desktop.
Save gfldex/2b43a001e6d5e6c0f03c0c3c3a837385 to your computer and use it in GitHub Desktop.
use v6;
my \pids = gather for dir('/proc') -> IO::Path:D $_ {
try { take .Int }
}
role StrictKeys[@keys] { method AT-KEY (\key) { (key ∈ @keys) ?? nextsame() !! fail "key «{key}» not found" } }
for pids -> $pid {
my %fields is default('<unkown>') does StrictKeys[<Name Pid Uid State VmRSS>]
= slurp("/proc/$pid/status").lines».split(":\t").flat».trim;
CATCH { when X::IO { next } }
%fields<Uid> = %fields<Uid>.split("\t")[0];
constant format = <%6s %-15s %-10s %-10s %-10s>.join("\t") ~ "\n";
FIRST printf format, <PID NAME USER STATE MEMORY>;
FIRST printf format, <------ --------------- ---------- ---------- ---------->;
printf format, %fields<Pid Name Uid State VmRSS>;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment