tools.ps.linux: recover from missing file in ps-cmdline, fixes #1120
parent
8bb96cbfd1
commit
9b5cb445ee
|
@ -1,23 +1,24 @@
|
||||||
! Copyright (C) 2012 Doug Coleman.
|
! Copyright (C) 2012 Doug Coleman.
|
||||||
! See http://factorcode.org/license.txt for BSD license.
|
! See http://factorcode.org/license.txt for BSD license.
|
||||||
USING: accessors assocs io.directories io.pathnames kernel
|
USING: accessors arrays assocs continuations io.directories kernel
|
||||||
math.parser prettyprint sequences splitting system
|
math.parser sequences splitting system tools.ps unix.linux.proc ;
|
||||||
tools.ps unix.linux.proc ;
|
|
||||||
IN: tools.ps.linux
|
IN: tools.ps.linux
|
||||||
|
|
||||||
! If cmdline is empty, read the filename from /proc/pid/stat
|
! If cmdline is empty, read the filename from /proc/pid/stat
|
||||||
: ps-cmdline ( path -- path string )
|
: ps-cmdline ( path -- string )
|
||||||
dup parse-proc-pid-cmdline [
|
dup parse-proc-pid-cmdline [
|
||||||
dup parse-proc-pid-stat filename>>
|
parse-proc-pid-stat filename>>
|
||||||
[ "()" member? ] trim
|
[ "()" member? ] trim
|
||||||
"[" "]" surround
|
"[" "]" surround
|
||||||
] [
|
] [
|
||||||
"\0" split " " join
|
nip "\0" split harvest " " join
|
||||||
] if-empty ;
|
] if-empty ;
|
||||||
|
|
||||||
|
: safe-ps-cmdline ( path -- string/f )
|
||||||
|
[ ps-cmdline ] [ 2drop f ] recover ;
|
||||||
|
|
||||||
M: linux ps ( -- assoc )
|
M: linux ps ( -- assoc )
|
||||||
"/proc" [
|
"/proc" [
|
||||||
"." directory-files
|
"." directory-files [ string>number ] filter
|
||||||
[ file-name string>number ] filter
|
[ dup safe-ps-cmdline 2array ] map sift-values
|
||||||
[ ps-cmdline ] { } map>assoc
|
|
||||||
] with-directory ;
|
] with-directory ;
|
||||||
|
|
Loading…
Reference in New Issue