C.2 Creating ProcessesA UNIX process can create a new process with the fork() system function.[6] fork() makes an identical copy of the calling process, with the exception that one process is identified as the parent or parent process, while the other is identified as the child or child process.
Note the following differences between child and parent:
The exec family of system functions lets a process change the program that it's running. Processes terminate when they call the _exit system function or when they generate an exception, such as an attempt to use an illegal instruction or address an invalid region of memory. UNIX uses special programs, called shells ( /bin/ksh, /bin/sh , and /bin/csh are all common shells) to read commands from the user and run other programs. The shell runs other programs by first executing one of the fork family of instructions to create a near-duplicate second process; the second process then uses one of the exec family of calls to run a new program, while the first process waits until the second process finishes. This technique is used to run virtually every program in UNIX , from small programs like /bin/ls to large programs like word processors. If all of the processes on the system suddenly die (or exit), the computer would be unusable, because there would be no way of starting a new process. In practice this scenario never occurs, for reasons that will be described later. |
|