Processes
=========

The procedures described in this section control the creation of subprocesses and the execution of programs.  They exported by both the posix-processes and posix structures.

 -- procedure: fork returns process id or #f
 -- procedure: fork-and-forget thunk returns unspecified
     Fork creates a new child process.  In the parent process, it returns the child's process id; in the child process, it returns #f.  Fork-and-forget calls THUNK in a new process; no process id is returned.  Fork-and-forget uses an intermediate process to avoid creating a zombie.

 -- procedure: process-id? object returns boolean
 -- procedure: process-id=? pida pidb returns boolean
 -- procedure: process-id->integer pid returns integer
 -- procedure: integer->process-id integer returns pid
     Process-id? is the disjoint type predicate for process ids. Process-id=? tests whether two process ids are the same. Process-id->integer & integer->process-id convert between Scheme48's opaque process id type and POSIX process id integers.

 -- procedure: process-id-exit-status pid returns integer or #f
 -- procedure: process-id-terminating-signal pid returns signal or #f
 -- procedure: wait-for-child-process pid returns unspecified
     If the process identified by PID exited normally or is running, process-id-exit-status and process-id-terminating-signal will both return #f.  If, however, it terminated abnormally, process-id-exit-status returns its exit status, and if it exited due to a signal then process-id-terminating-signal returns the signal due to which it exited.  Wait-for-child-process blocks the current process until the process identified by PID has terminated.  Scheme48 may reap child processes before the user requests their exit status, but it does not always do so.

 -- procedure: exit status returns does not return
     Terminates the current process with the integer STATUS as its exit status.

 -- procedure: exec program argument ... returns does not return
 -- procedure: exec-with-environment program env argument ... returns does not return
 -- procedure: exec-file filename argument ... returns does not return
 -- procedure: exec-file-with-environment filename env argument ... returns does not return
     These all replace the current program with a new one.  They differ in how the program is found and what process environment the program should receive.  Exec & exec-with-environment look up the program in the search path (the PATH environment variable), while exec-file & exec-file-with-environment execute a particular file.  The environment is either inherited from the current process, in the cases of exec & exec-file, or explicitly specified, in the cases of exec-with-environment & exec-file-with-environment.  PROGRAM, FILENAME, & all ARGUMENTs should be strings.  ENV should be a list of strings of the form "NAME=VALUE".  When the new program is invoked, its arguments consist of the program name prepended to the remaining specified arguments.

 -- procedure: exec-with-alias name lookup? maybe-env arguments returns does not return
     General omnibus procedure that subsumes the other exec variants. NAME is looked up in the search path if LOOKUP? is true or used as an ordinary filename if it is false.  MAYBE-ENV is either #f, in which case the new program's environment should be inherited from the current process, or a list of strings of the above form for environments, which specifies the new program's environment. ARGUMENTS is a list of all of the program's arguments; exec-with-alias does not prepend NAME to that list (hence -with-alias).