2012-02-03 20:30:34 -05:00
|
|
|
! Copyright (C) 2012 Doug Coleman.
|
|
|
|
! See http://factorcode.org/license.txt for BSD license.
|
|
|
|
USING: assocs io.directories io.encodings.utf8 io.files
|
|
|
|
io.pathnames kernel math.parser prettyprint sequences splitting
|
|
|
|
unicode.categories ;
|
|
|
|
IN: tools.ps
|
|
|
|
|
2012-06-18 12:51:07 -04:00
|
|
|
! Only in Linux 3
|
2012-02-03 20:30:34 -05:00
|
|
|
: ps-comm ( path -- string )
|
|
|
|
"/comm" append utf8 file-contents "\0" split " " join
|
|
|
|
[ blank? ] trim "[" "]" surround ;
|
|
|
|
|
2012-06-18 12:51:07 -04:00
|
|
|
: parse-stat ( string -- program-name )
|
|
|
|
" " split
|
|
|
|
second
|
|
|
|
[ CHAR: ( = ] trim-head
|
|
|
|
[ CHAR: ) = ] trim-tail
|
|
|
|
"[" "]" surround ;
|
|
|
|
|
|
|
|
: ps-stat ( path -- string )
|
|
|
|
"/stat" append utf8 file-contents parse-stat ;
|
|
|
|
|
2012-02-03 20:30:34 -05:00
|
|
|
: ps-cmdline ( path -- path string )
|
|
|
|
dup "/cmdline" append utf8 file-contents
|
2012-06-18 12:51:07 -04:00
|
|
|
[ dup ps-stat ] [ "\0" split " " join ] if-empty ;
|
2012-02-03 20:30:34 -05:00
|
|
|
|
|
|
|
: ps ( -- assoc )
|
|
|
|
"/proc" [
|
|
|
|
"." directory-files [ file-name string>number ] filter
|
|
|
|
[ ps-cmdline ] { } map>assoc
|
|
|
|
] with-directory ;
|
|
|
|
|
|
|
|
: ps. ( -- )
|
|
|
|
ps simple-table. ;
|