1 USING: kernel alien.c-types alien.data alien.strings sequences
2 math alien.syntax unix namespaces continuations threads assocs
3 io.backend.unix io.encodings.utf8 unix.types unix.utilities fry ;
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 ( c-string path, c-string* argv ) ;
15 FUNCTION: int execvp ( c-string path, c-string* argv ) ;
16 FUNCTION: int execve ( c-string path, c-string* argv, c-string* 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 ] 2dip if-zero ; inline
44 FUNCTION: int kill ( pid_t pid, int sig ) ;
46 CONSTANT: PRIO_PROCESS 0
50 CONSTANT: PRIO_MIN -20
53 ! which/who = 0 for current process
54 FUNCTION: int getpriority ( int which, int who ) ;
55 FUNCTION: int setpriority ( int which, int who, int prio ) ;
57 : set-priority ( n -- )
58 [ 0 0 ] dip setpriority io-error ;
67 CONSTANT: WCONTINUED 8
68 CONSTANT: WNOWAIT HEX: 1000000
72 : WTERMSIG ( status -- value )
73 HEX: 7f bitand ; inline
75 : WIFEXITED ( status -- ? )
78 : WEXITSTATUS ( status -- value )
79 HEX: ff00 bitand -8 shift ; inline
81 : WIFSIGNALED ( status -- ? )
82 HEX: 7f bitand 1 + -1 shift 0 > ; inline
84 : WCOREFLAG ( -- value )
87 : WCOREDUMP ( status -- ? )
88 WCOREFLAG bitand 0 = not ; inline
90 : WIFSTOPPED ( status -- ? )
91 HEX: ff bitand HEX: 7f = ; inline
93 : WSTOPSIG ( status -- value )
96 FUNCTION: pid_t wait ( int* status ) ;
97 FUNCTION: pid_t waitpid ( pid_t wpid, int* status, int options ) ;
99 : wait-for-pid ( pid -- status )
100 0 <int> [ 0 waitpid drop ] keep *int WEXITSTATUS ;