Next: , Up: POSIX interface


8.1 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 –> process id or #f
— procedure: fork-and-forget thunk –> 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 –> boolean
— procedure: process-id=? pida pidb –> boolean
— procedure: process-id->integer pid –> integer
— procedure: integer->process-id integer –> 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 –> integer or #f
— procedure: process-id-terminating-signal pid –> signal or #f
— procedure: wait-for-child-process pid –> 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 –> does not return

Terminates the current process with the integer status as its exit status.

— procedure: exec program argument ... –> does not return
— procedure: exec-with-environment program env argument ... –> does not return
— procedure: exec-file filename argument ... –> does not return
— procedure: exec-file-with-environment filename env argument ... –> 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 –> 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).