2014-12-24 14:16:11 -05:00
|
|
|
USING: alien.c-types alien.data alien.syntax io.encodings.utf8
|
|
|
|
kernel libc math sequences unix unix.types unix.utilities ;
|
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-05-14 00:09:39 -04:00
|
|
|
FUNCTION: pid_t fork ( ) ;
|
|
|
|
|
|
|
|
: fork-process ( -- pid ) [ fork ] unix-system-call ;
|
|
|
|
|
2010-02-23 14:42:02 -05:00
|
|
|
FUNCTION: int execv ( c-string path, c-string* argv ) ;
|
|
|
|
FUNCTION: int execvp ( c-string path, c-string* argv ) ;
|
|
|
|
FUNCTION: int execve ( c-string path, c-string* argv, c-string* envp ) ;
|
2008-05-14 00:09:39 -04:00
|
|
|
|
2007-11-14 18:32:29 -05:00
|
|
|
: exec ( pathname argv -- int )
|
2008-10-18 22:15:43 -04:00
|
|
|
[ utf8 malloc-string ] [ utf8 strings>alien ] bi* execv ;
|
2007-11-14 18:32:29 -05:00
|
|
|
|
|
|
|
: exec-with-path ( filename argv -- int )
|
2008-10-18 22:15:43 -04:00
|
|
|
[ utf8 malloc-string ] [ utf8 strings>alien ] bi* execvp ;
|
2007-11-14 18:32:29 -05:00
|
|
|
|
|
|
|
: exec-with-env ( filename argv envp -- int )
|
2008-10-18 22:15:43 -04:00
|
|
|
[ utf8 malloc-string ]
|
|
|
|
[ utf8 strings>alien ]
|
|
|
|
[ utf8 strings>alien ] tri* execve ;
|
2007-11-14 18:32:29 -05:00
|
|
|
|
2008-01-20 17:07:18 -05:00
|
|
|
: exec-args ( seq -- int )
|
2014-12-24 14:16:11 -05:00
|
|
|
[ first ] keep exec ;
|
2007-11-14 18:32:29 -05:00
|
|
|
|
2008-01-20 17:07:18 -05:00
|
|
|
: exec-args-with-path ( seq -- int )
|
2014-12-24 14:16:11 -05:00
|
|
|
[ first ] keep 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 )
|
2014-12-24 14:16:11 -05:00
|
|
|
[ [ first ] keep ] dip exec-with-env ;
|
2007-11-14 18:32:29 -05:00
|
|
|
|
2008-01-20 17:07:18 -05:00
|
|
|
: with-fork ( child parent -- )
|
2010-04-15 01:45:30 -04:00
|
|
|
[ fork-process ] 2dip if-zero ; inline
|
2007-11-15 18:49:43 -05:00
|
|
|
|
2008-05-14 01:45:43 -04:00
|
|
|
FUNCTION: int kill ( pid_t pid, int sig ) ;
|
2011-11-08 13:42:51 -05:00
|
|
|
FUNCTION: int raise ( int sig ) ;
|
|
|
|
|
2008-05-14 01:45:43 -04:00
|
|
|
|
2008-12-16 02:12:36 -05:00
|
|
|
CONSTANT: PRIO_PROCESS 0
|
|
|
|
CONSTANT: PRIO_PGRP 1
|
|
|
|
CONSTANT: PRIO_USER 2
|
2008-05-14 01:45:43 -04:00
|
|
|
|
2008-12-16 02:12:36 -05:00
|
|
|
CONSTANT: PRIO_MIN -20
|
|
|
|
CONSTANT: PRIO_MAX 20
|
2008-05-14 01:45:43 -04:00
|
|
|
|
|
|
|
! which/who = 0 for current process
|
|
|
|
FUNCTION: int getpriority ( int which, int who ) ;
|
|
|
|
FUNCTION: int setpriority ( int which, int who, int prio ) ;
|
2008-03-24 19:02:39 -04:00
|
|
|
|
|
|
|
: set-priority ( n -- )
|
2008-12-16 02:12:36 -05:00
|
|
|
[ 0 0 ] dip setpriority io-error ;
|
2008-05-14 01:45:43 -04:00
|
|
|
|
|
|
|
! Flags for waitpid
|
|
|
|
|
2008-12-16 02:12:36 -05:00
|
|
|
CONSTANT: WNOHANG 1
|
|
|
|
CONSTANT: WUNTRACED 2
|
2008-05-14 01:45:43 -04:00
|
|
|
|
2008-12-16 02:12:36 -05:00
|
|
|
CONSTANT: WSTOPPED 2
|
|
|
|
CONSTANT: WEXITED 4
|
|
|
|
CONSTANT: WCONTINUED 8
|
2011-11-23 21:49:33 -05:00
|
|
|
CONSTANT: WNOWAIT 0x1000000
|
2008-05-14 01:45:43 -04:00
|
|
|
|
|
|
|
! Examining status
|
|
|
|
|
|
|
|
: WTERMSIG ( status -- value )
|
2011-11-23 21:49:33 -05:00
|
|
|
0x7f bitand ; inline
|
2008-05-14 01:45:43 -04:00
|
|
|
|
|
|
|
: WIFEXITED ( status -- ? )
|
2008-12-10 18:30:07 -05:00
|
|
|
WTERMSIG 0 = ; inline
|
2008-05-14 01:45:43 -04:00
|
|
|
|
|
|
|
: WEXITSTATUS ( status -- value )
|
2011-11-23 21:49:33 -05:00
|
|
|
0xff00 bitand -8 shift ; inline
|
2008-05-14 01:45:43 -04:00
|
|
|
|
|
|
|
: WIFSIGNALED ( status -- ? )
|
2011-11-23 21:49:33 -05:00
|
|
|
0x7f bitand 1 + -1 shift 0 > ; inline
|
2008-05-14 01:45:43 -04:00
|
|
|
|
|
|
|
: WCOREFLAG ( -- value )
|
2011-11-23 21:49:33 -05:00
|
|
|
0x80 ; inline
|
2008-05-14 01:45:43 -04:00
|
|
|
|
|
|
|
: WCOREDUMP ( status -- ? )
|
2008-12-10 18:30:07 -05:00
|
|
|
WCOREFLAG bitand 0 = not ; inline
|
2008-05-14 01:45:43 -04:00
|
|
|
|
|
|
|
: WIFSTOPPED ( status -- ? )
|
2011-11-23 21:49:33 -05:00
|
|
|
0xff bitand 0x7f = ; inline
|
2008-05-14 01:45:43 -04:00
|
|
|
|
|
|
|
: WSTOPSIG ( status -- value )
|
|
|
|
WEXITSTATUS ; inline
|
|
|
|
|
|
|
|
FUNCTION: pid_t wait ( int* status ) ;
|
|
|
|
FUNCTION: pid_t waitpid ( pid_t wpid, int* status, int options ) ;
|