]> gitweb.factorcode.org Git - factor.git/blobdiff - basis/unix/process/process.factor
use radix literals
[factor.git] / basis / unix / process / process.factor
index 2912f8b744326aeac16f909ecb738acd036b4bab..f0d12d70d3317c158d47480bdc866cd86514bd7d 100644 (file)
@@ -1,6 +1,7 @@
 USING: kernel alien.c-types alien.data alien.strings sequences
 math alien.syntax unix namespaces continuations threads assocs
-io.backend.unix io.encodings.utf8 unix.utilities fry ;
+io.backend.unix io.encodings.utf8 unix.types unix.utilities fry 
+unix.ffi ;
 IN: unix.process
 
 ! Low-level Unix process launching utilities. These are used
@@ -11,9 +12,9 @@ FUNCTION: pid_t fork ( ) ;
 
 : fork-process ( -- pid ) [ fork ] unix-system-call ;
 
-FUNCTION: int execv ( char* path, char** argv ) ;
-FUNCTION: int execvp ( char* path, char** argv ) ;
-FUNCTION: int execve ( char* path, char** argv, char** envp ) ;
+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 ) ;
 
 : exec ( pathname argv -- int )
     [ utf8 malloc-string ] [ utf8 strings>alien ] bi* execv ;
@@ -36,13 +37,11 @@ FUNCTION: int execve ( char* path, char** argv, char** envp ) ;
     [ [ first ] [ ] bi ] dip exec-with-env ;
 
 : with-fork ( child parent -- )
-    [ [ fork-process dup zero? ] dip '[ drop @ ] ] dip
-    if ; inline
-
-CONSTANT: SIGKILL 9
-CONSTANT: SIGTERM 15
+    [ fork-process ] 2dip if-zero ; inline
 
 FUNCTION: int kill ( pid_t pid, int sig ) ;
+FUNCTION: int raise ( int sig ) ;
+
 
 CONSTANT: PRIO_PROCESS 0
 CONSTANT: PRIO_PGRP 1
@@ -66,36 +65,33 @@ CONSTANT: WUNTRACED 2
 CONSTANT: WSTOPPED   2
 CONSTANT: WEXITED    4
 CONSTANT: WCONTINUED 8
-CONSTANT: WNOWAIT    HEX: 1000000
+CONSTANT: WNOWAIT    0x1000000
 
 ! Examining status
 
 : WTERMSIG ( status -- value )
-    HEX: 7f bitand ; inline
+    0x7f bitand ; inline
 
 : WIFEXITED ( status -- ? )
     WTERMSIG 0 = ; inline
 
 : WEXITSTATUS ( status -- value )
-    HEX: ff00 bitand -8 shift ; inline
+    0xff00 bitand -8 shift ; inline
 
 : WIFSIGNALED ( status -- ? )
-    HEX: 7f bitand 1 + -1 shift 0 > ; inline
+    0x7f bitand 1 + -1 shift 0 > ; inline
 
 : WCOREFLAG ( -- value )
-    HEX: 80 ; inline
+    0x80 ; inline
 
 : WCOREDUMP ( status -- ? )
     WCOREFLAG bitand 0 = not ; inline
 
 : WIFSTOPPED ( status -- ? )
-    HEX: ff bitand HEX: 7f = ; inline
+    0xff bitand 0x7f = ; inline
 
 : WSTOPSIG ( status -- value )
     WEXITSTATUS ; inline
 
 FUNCTION: pid_t wait ( int* status ) ;
 FUNCTION: pid_t waitpid ( pid_t wpid, int* status, int options ) ;
-
-: wait-for-pid ( pid -- status )
-    0 <int> [ 0 waitpid drop ] keep *int WEXITSTATUS ;