factor/basis/tools/ps/linux/linux.factor

25 lines
782 B
Factor
Raw Normal View History

2013-04-25 12:12:42 -04:00
! Copyright (C) 2012 Doug Coleman.
! See http://factorcode.org/license.txt for BSD license.
USING: accessors arrays assocs continuations io.directories kernel
math.parser sequences splitting system tools.ps unix.linux.proc ;
2013-04-25 12:12:42 -04:00
IN: tools.ps.linux
! If cmdline is empty, read the filename from /proc/pid/stat
: ps-cmdline ( path -- string )
2013-04-25 12:12:42 -04:00
dup parse-proc-pid-cmdline [
parse-proc-pid-stat filename>>
2013-04-25 12:12:42 -04:00
[ "()" member? ] trim
"[" "]" surround
] [
nip "\0" split harvest " " join
2013-04-25 12:12:42 -04:00
] if-empty ;
: safe-ps-cmdline ( path -- string/f )
[ ps-cmdline ] [ 2drop f ] recover ;
2013-04-25 12:12:42 -04:00
M: linux ps ( -- assoc )
"/proc" [
"." directory-files [ string>number ] filter
[ dup safe-ps-cmdline 2array ] map sift-values
2013-04-25 12:12:42 -04:00
] with-directory ;