tools.ps: Fix ps tool for linux < 3.

db4
Doug Coleman 2012-06-18 09:51:07 -07:00
parent 0fb3b968ed
commit fd2803a916
1 changed files with 12 additions and 1 deletions

View File

@ -5,13 +5,24 @@ io.pathnames kernel math.parser prettyprint sequences splitting
unicode.categories ;
IN: tools.ps
! Only in Linux 3
: ps-comm ( path -- string )
"/comm" append utf8 file-contents "\0" split " " join
[ blank? ] trim "[" "]" surround ;
: 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 ;
: ps-cmdline ( path -- path string )
dup "/cmdline" append utf8 file-contents
[ dup ps-comm ] [ "\0" split " " join ] if-empty ;
[ dup ps-stat ] [ "\0" split " " join ] if-empty ;
: ps ( -- assoc )
"/proc" [