Next: posix process fork fds, Up: posix process fork [Index]
Interface to the C function fork()
, (libc)fork. The behaviour depends upon the number of arguments:
fork()
, else raise an exception. The return
value is: 0
in the child process; the child process pid in the
parent.
When forking a process we must remember about input/output ports:
flush-ports-in-close-on-exec-mode
; flush-ports-in-close-on-exec-mode, for details.
close-ports-in-close-on-exec-mode
; close-ports-in-close-on-exec-mode, for details.
we must also remember that some file descriptors are marked to be “closed on exec”.
Here is a simple example of forking a process:
#!r6rs (import (vicare) (prefix (vicare posix) px.)) (px.fork (lambda (child-pid) (printf "in parent pid = ~a, child pid = ~s\n" (px.getpid) child-pid) (flush-output-port (current-output-port))) (lambda () (printf "in child, pid = ~a\n" (px.getpid)) (flush-output-port (current-output-port)) (exit))) (printf "here we are in the parent\n") (flush-output-port (current-output-port))