next up previous contents index
Next: Other Process State Up: Topaz Operating System Interface Previous: Signals

Process Creation

            UNIX provides simple but powerful facilities for creating processes and executing program images, involving three main system calls: fork, wait, and exec. fork creates a child process whose memory, set of open files, and other system-maintained state components are all copied from the calling process. wait waits for the next termination of a child of the calling process; there is also a nonblocking form of wait and a signal SIGCHLD sent by the system whenever a child process terminates. exec overlays the address space of the calling process with a new program image.

Typically UNIX programs use these facilities in one of two stylized ways. One is to create an extra thread of control; for example a ``terminal emulator'' program uses a pair of processes for full-duplex communication with a remote system. The other is to run a new program image; for example, the shell runs each command in a new child process.

      In Topaz, the way to create an extra thread of control is simply to fork a new thread within the same process. Topaz must still provide a mechanism for running a new program image, and the UNIX method won't do. In UNIX, the parent calls fork; the child (initially executing the same program image as the parent) makes any necessary changes to its process state (e.g., opening and closing files or changing the user id), and finally calls exec to overlay itself with the new program image. Since the fork-exec sequence involves a large amount of shared mutable state (the entire child process), it isn't surprising that it doesn't work for Topaz. Would fork copy all threads? In the Apollo and Mach systems, only the thread that calls fork is copied [17]. But what happens if locks were held by other threads in the parent process? If fork copied all threads, what would it mean to copy a thread blocked in a system call?

        To address this problem, Topaz replaces fork and exec with a single new procedure StartProcess, which accepts as parameters all the modifiable components of a process state (namely anything that could be changed between a call to fork and the subsequent call to exec, such as the set of open files and the user id). Topaz also replaces wait with WaitForChild, which waits for the termination of a specific child process.

There are several reasons for not merging the functions of StartProcess and WaitForChild into a single procedure that would block until termination of the child process. As it stands, StartProcess returns the process identifier of the new process and WaitForChild returns a status value indicating whether the child terminated or temporarily stopped. These features allow a process to be observed and controlled while it executes, in a way compatible with 4.2BSD job control.


next up previous contents index
Next: Other Process State Up: Topaz Operating System Interface Previous: Signals
Paul McJones
8/28/1997