Last active
October 6, 2016 23:45
-
-
Save gfldex/2b43a001e6d5e6c0f03c0c3c3a837385 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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