| 
									
										
										
										
											2008-01-20 17:07:18 -05:00
										 |  |  | USING: kernel alien.c-types sequences math unix | 
					
						
							|  |  |  | combinators.cleave vectors kernel namespaces continuations | 
					
						
							| 
									
										
										
										
											2008-02-05 18:31:27 -05:00
										 |  |  | threads assocs vectors io.unix.backend ;
 | 
					
						
							| 
									
										
										
										
											2007-11-14 18:32:29 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | IN: unix.process | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-01-20 17:07:18 -05:00
										 |  |  | ! Low-level Unix process launching utilities. These are used | 
					
						
							|  |  |  | ! to implement io.launcher on Unix. User code should use | 
					
						
							|  |  |  | ! io.launcher instead. | 
					
						
							| 
									
										
										
										
											2007-11-14 18:32:29 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-02-05 18:07:37 -05:00
										 |  |  | : >argv ( seq -- alien )
 | 
					
						
							|  |  |  |     [ malloc-char-string ] map f add >c-void*-array ;
 | 
					
						
							| 
									
										
										
										
											2007-11-14 18:32:29 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | : exec ( pathname argv -- int )
 | 
					
						
							| 
									
										
										
										
											2008-01-20 17:07:18 -05:00
										 |  |  |     [ malloc-char-string ] [ >argv ] bi* execv ;
 | 
					
						
							| 
									
										
										
										
											2007-11-14 18:32:29 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | : exec-with-path ( filename argv -- int )
 | 
					
						
							| 
									
										
										
										
											2008-01-20 17:07:18 -05:00
										 |  |  |     [ malloc-char-string ] [ >argv ] bi* execvp ;
 | 
					
						
							| 
									
										
										
										
											2007-11-14 18:32:29 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | : exec-with-env ( filename argv envp -- int )
 | 
					
						
							| 
									
										
										
										
											2008-01-20 17:07:18 -05:00
										 |  |  |     [ malloc-char-string ] [ >argv ] [ >argv ] tri* execve ;
 | 
					
						
							| 
									
										
										
										
											2007-11-14 18:32:29 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-01-20 17:07:18 -05:00
										 |  |  | : exec-args ( seq -- int )
 | 
					
						
							|  |  |  |     [ first ] [ ] bi exec ;
 | 
					
						
							| 
									
										
										
										
											2007-11-14 18:32:29 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-01-20 17:07:18 -05:00
										 |  |  | : exec-args-with-path ( seq -- int )
 | 
					
						
							|  |  |  |     [ first ] [ ] bi exec-with-path ;
 | 
					
						
							| 
									
										
										
										
											2007-11-14 18:32:29 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-01-20 17:07:18 -05:00
										 |  |  | : exec-args-with-env  ( seq seq -- int )
 | 
					
						
							|  |  |  |     >r [ first ] [ ] bi r> exec-with-env ;
 | 
					
						
							| 
									
										
										
										
											2007-11-14 18:32:29 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-01-20 17:07:18 -05:00
										 |  |  | : with-fork ( child parent -- )
 | 
					
						
							| 
									
										
										
										
											2008-02-05 18:07:37 -05:00
										 |  |  |     fork dup io-error dup zero? -roll swap curry if ; inline
 | 
					
						
							| 
									
										
										
										
											2007-11-15 18:49:43 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-01-20 17:07:18 -05:00
										 |  |  | : wait-for-pid ( pid -- status )
 | 
					
						
							| 
									
										
										
										
											2008-02-04 20:58:07 -05:00
										 |  |  |     0 <int> [ 0 waitpid drop ] keep *int WEXITSTATUS ;
 |