factor/extra/unix/process/process.factor

36 lines
1.0 KiB
Factor
Raw Normal View History

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
! 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 )
[ malloc-char-string ] [ >argv ] bi* execv ;
2007-11-14 18:32:29 -05:00
: exec-with-path ( filename argv -- int )
[ malloc-char-string ] [ >argv ] bi* execvp ;
2007-11-14 18:32:29 -05:00
: exec-with-env ( filename argv envp -- int )
[ malloc-char-string ] [ >argv ] [ >argv ] tri* execve ;
2007-11-14 18:32:29 -05:00
: exec-args ( seq -- int )
[ first ] [ ] bi exec ;
2007-11-14 18:32:29 -05:00
: exec-args-with-path ( seq -- int )
[ first ] [ ] bi exec-with-path ;
2007-11-14 18:32:29 -05:00
: exec-args-with-env ( seq seq -- int )
>r [ first ] [ ] bi r> exec-with-env ;
2007-11-14 18:32:29 -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
: wait-for-pid ( pid -- status )
2008-02-04 20:58:07 -05:00
0 <int> [ 0 waitpid drop ] keep *int WEXITSTATUS ;