| 
									
										
										
										
											2013-04-25 12:12:42 -04:00
										 |  |  | ! Copyright (C) 2012 Doug Coleman. | 
					
						
							|  |  |  | ! See http://factorcode.org/license.txt for BSD license. | 
					
						
							| 
									
										
										
										
											2015-10-20 10:55:48 -04:00
										 |  |  | USING: accessors arrays assocs continuations io.directories kernel | 
					
						
							|  |  |  | math.parser sequences splitting system tools.ps unix.linux.proc ;
 | 
					
						
							| 
									
										
										
										
											2013-04-25 12:12:42 -04:00
										 |  |  | IN: tools.ps.linux | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ! If cmdline is empty, read the filename from /proc/pid/stat | 
					
						
							| 
									
										
										
										
											2015-10-20 10:55:48 -04:00
										 |  |  | : ps-cmdline ( path -- string )
 | 
					
						
							| 
									
										
										
										
											2013-04-25 12:12:42 -04:00
										 |  |  |     dup parse-proc-pid-cmdline [ | 
					
						
							| 
									
										
										
										
											2015-10-20 10:55:48 -04:00
										 |  |  |         parse-proc-pid-stat filename>> | 
					
						
							| 
									
										
										
										
											2013-04-25 12:12:42 -04:00
										 |  |  |         [ "()" member? ] trim
 | 
					
						
							|  |  |  |         "[" "]" surround
 | 
					
						
							|  |  |  |     ] [ | 
					
						
							| 
									
										
										
										
											2015-10-20 10:55:48 -04:00
										 |  |  |         nip "\0" split harvest " " join
 | 
					
						
							| 
									
										
										
										
											2013-04-25 12:12:42 -04:00
										 |  |  |     ] if-empty ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-10-20 10:55:48 -04:00
										 |  |  | : safe-ps-cmdline ( path -- string/f )
 | 
					
						
							|  |  |  |     [ ps-cmdline ] [ 2drop f ] recover ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-09 17:41:17 -04:00
										 |  |  | M: linux ps | 
					
						
							| 
									
										
										
										
											2013-04-25 12:12:42 -04:00
										 |  |  |     "/proc" [ | 
					
						
							| 
									
										
										
										
											2015-10-20 10:55:48 -04:00
										 |  |  |         "." directory-files [ string>number ] filter
 | 
					
						
							|  |  |  |         [ dup safe-ps-cmdline 2array ] map sift-values
 | 
					
						
							| 
									
										
										
										
											2013-04-25 12:12:42 -04:00
										 |  |  |     ] with-directory ;
 |