Scheme 48 Manual | Contents | In Chapter: Access to POSIX
Previous: Process primitives | Next: Process primitives

Process primitives

The procedures described in this section control the creation of processes and the execution of programs. They are in the structures posix-process and posix.

Process creation and termination

Fork creates a new child process and returns the child's process-id in the parent and #f in the child. 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 process.

Process-id? is a predicate for process-ids, process-id=? compares two to see if they are the same, and process-id-uid returns the actual Unix id. Process-id->integer and integer->process-id convert process ids to and from integers.

If a process terminates normally process-id-exit-status will return its exit status. If the process is still running or was terminated by a signal then process-id-exit-status will return #f. Similarly, if a child process was terminated by a signal process-id-terminating-signal will return that signal and will return #f if the process is still running or terminated normally. Wait-for-child-process blocks until the child process terminates. Scheme 48 may reap child processes before the user requests their exit status, but it does not always do so.

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


All of these replace the current program with a new one. They differ in how the new program is found, what its environment is, and what arguments it is passed. Exec and exec-with-environment look up the new program in the search path, while exec-file and exec-file-with-environment execute a particular file. The environment is either inherited from the current process (exec and exec-file) or given as an argument (...-with-environment). Program-name and filename and any argi should be strings. Env should be a list of strings of the form "name=value". The first four procedures add their first argument, program-name or filename, before the arg0 ... arguments.

Exec-with-alias is an omnibus procedure that subsumes the other four. Name is looked up in the search path if lookup? is true and is used as a filename otherwise. Maybe-env is either a list of strings for the environment of the new program or #f in which case the new program inherits its environment from the current one. Arguments should be a list of strings; unlike with the other four procedures, name is not added to this list (hence -with-alias).

Previous: Process primitives | Next: Process primitives