2012-02-03 20:30:34 -05:00
|
|
|
! Copyright (C) 2012 Doug Coleman.
|
|
|
|
! See http://factorcode.org/license.txt for BSD license.
|
2013-02-23 15:45:45 -05:00
|
|
|
USING: accessors assocs io.directories io.pathnames kernel
|
|
|
|
math.parser prettyprint sequences splitting unix.linux.proc ;
|
2012-02-03 20:30:34 -05:00
|
|
|
IN: tools.ps
|
|
|
|
|
2013-02-23 15:45:45 -05:00
|
|
|
! If cmdline is empty, read the filename from /proc/pid/stat
|
2012-02-03 20:30:34 -05:00
|
|
|
: ps-cmdline ( path -- path string )
|
2013-02-23 15:45:45 -05:00
|
|
|
dup parse-proc-pid-cmdline [
|
|
|
|
dup parse-proc-pid-stat filename>>
|
|
|
|
[ "()" member? ] trim
|
|
|
|
"[" "]" surround
|
|
|
|
] [
|
|
|
|
"\0" split " " join
|
|
|
|
] if-empty ;
|
2012-02-03 20:30:34 -05:00
|
|
|
|
|
|
|
: ps ( -- assoc )
|
|
|
|
"/proc" [
|
2013-02-23 15:45:45 -05:00
|
|
|
"." directory-files
|
|
|
|
[ file-name string>number ] filter
|
2012-02-03 20:30:34 -05:00
|
|
|
[ ps-cmdline ] { } map>assoc
|
|
|
|
] with-directory ;
|
|
|
|
|
|
|
|
: ps. ( -- )
|
|
|
|
ps simple-table. ;
|