 USING: accessors arrays combinators combinators.smart
 io.encodings.utf8 io.files kernel math math.order math.parser
 memoize sequences sorting.slots splitting splitting.monotonic
-strings ;
+strings io.pathnames ;
 IN: unix.linux.proc
 
 ! /proc/*


! /proc/pid/*

: proc-pid-path ( pid string -- path )
    [ "/proc/" ] 2dip
    [ number>string "/" append ] dip
    3append ;

: proc-pid-first-line ( pid string -- string )
    proc-pid-path utf8 file-lines first ;

: proc-pid-cmdline ( pid -- string )
    "cmdline" proc-pid-first-line ;

TUPLE: pid-stat pid filename state parent-pid group-id session-id terminal#
    terminal-group-id task-flags

    env-start env-end
    exit-code ;

: parse-proc-pid-stat ( pid -- stat )
    "stat" proc-pid-path
    proc-first-line
    " " split harvest
    [ dup string>number [ nip ] when* ] map
    [ pid-stat boa ] input<sequence ;
