From fd2803a9161c3a2f372176fa0df759cc45d82c02 Mon Sep 17 00:00:00 2001 From: Doug Coleman <doug.coleman@gmail.com> Date: Mon, 18 Jun 2012 09:51:07 -0700 Subject: [PATCH] tools.ps: Fix ps tool for linux < 3. --- basis/tools/ps/ps.factor | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/basis/tools/ps/ps.factor b/basis/tools/ps/ps.factor index caf567a9eb..50240acfcb 100644 --- a/basis/tools/ps/ps.factor +++ b/basis/tools/ps/ps.factor @@ -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" [