Last active
October 6, 2016 23:45
Star
You must be signed in to star a gist
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