1 USING: kernel alien.c-types alien.strings sequences math alien.syntax unix
2 vectors kernel namespaces continuations threads assocs vectors
3 io.backend.unix io.encodings.utf8 unix.utilities ;
6 ! Low-level Unix process launching utilities. These are used
7 ! to implement io.launcher on Unix. User code should use
10 FUNCTION: pid_t fork ( ) ;
12 : fork-process ( -- pid ) [ fork ] unix-system-call ;
14 FUNCTION: int execv ( char* path, char** argv ) ;
15 FUNCTION: int execvp ( char* path, char** argv ) ;
16 FUNCTION: int execve ( char* path, char** argv, char** envp ) ;
18 : exec ( pathname argv -- int )
19 [ utf8 malloc-string ] [ utf8 strings>alien ] bi* execv ;
21 : exec-with-path ( filename argv -- int )
22 [ utf8 malloc-string ] [ utf8 strings>alien ] bi* execvp ;
24 : exec-with-env ( filename argv envp -- int )
25 [ utf8 malloc-string ]
26 [ utf8 strings>alien ]
27 [ utf8 strings>alien ] tri* execve ;
29 : exec-args ( seq -- int )
30 [ first ] [ ] bi exec ;
32 : exec-args-with-path ( seq -- int )
33 [ first ] [ ] bi exec-with-path ;
35 : exec-args-with-env ( seq seq -- int )
36 [ [ first ] [ ] bi ] dip exec-with-env ;
38 : with-fork ( child parent -- )
39 [ [ fork-process dup zero? ] dip [ drop ] prepose ] dip
45 FUNCTION: int kill ( pid_t pid, int sig ) ;
47 CONSTANT: PRIO_PROCESS 0
51 CONSTANT: PRIO_MIN -20
54 ! which/who = 0 for current process
55 FUNCTION: int getpriority ( int which, int who ) ;
56 FUNCTION: int setpriority ( int which, int who, int prio ) ;
58 : set-priority ( n -- )
59 [ 0 0 ] dip setpriority io-error ;
68 CONSTANT: WCONTINUED 8
69 CONSTANT: WNOWAIT HEX: 1000000
73 : WTERMSIG ( status -- value )
74 HEX: 7f bitand ; inline
76 : WIFEXITED ( status -- ? )
79 : WEXITSTATUS ( status -- value )
80 HEX: ff00 bitand -8 shift ; inline
82 : WIFSIGNALED ( status -- ? )
83 HEX: 7f bitand 1+ -1 shift 0 > ; inline
85 : WCOREFLAG ( -- value )
88 : WCOREDUMP ( status -- ? )
89 WCOREFLAG bitand 0 = not ; inline
91 : WIFSTOPPED ( status -- ? )
92 HEX: ff bitand HEX: 7f = ; inline
94 : WSTOPSIG ( status -- value )
97 FUNCTION: pid_t wait ( int* status ) ;
98 FUNCTION: pid_t waitpid ( pid_t wpid, int* status, int options ) ;
100 : wait-for-pid ( pid -- status )
101 0 <int> [ 0 waitpid drop ] keep *int WEXITSTATUS ;