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

24 lines
702 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 assocs io.directories io.pathnames kernel
2013-04-25 18:59:25 -04:00
math.parser prettyprint sequences splitting system
2013-04-25 19:01:30 -04:00
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 -- path string )
dup parse-proc-pid-cmdline [
dup parse-proc-pid-stat filename>>
[ "()" member? ] trim
"[" "]" surround
] [
"\0" split " " join
] if-empty ;
M: linux ps ( -- assoc )
"/proc" [
"." directory-files
[ file-name string>number ] filter
[ ps-cmdline ] { } map>assoc
] with-directory ;