Information Technology Reference
In-Depth Information
pid = fork();
if (pid == 0)
exec(...);
else
wait(pid);
main () {
...
fork
exec
}
pid = fork();
if (pid == 0)
exec(...);
else
wait(pid);
pid = fork();
if (pid == 0)
exec(...);
else
wait(pid);
wait
Figure3.4: The operation of the UNIX fork and exec system calls.
new program and start running it. Although it may seem incredibly wasteful to
make a complete copy of a program just to throw it away during exec , in a later
chapter we will describe a set of techniques that allow UNIX fork and exec to
be implemented with very little copying and a modest amount of bookkeeping
by the kernel.
With this design, UNIX fork takes no arguments and returns an integer.
UNIX exec takes only two arguments (the name of the program to run and an
array of arguments to pass to the program). In part because of its simplicity,
this interface has remained nearly unchanged since UNIX was designed in the
early 70's. (Although the interface hasn't changed, the word fork is now a bit
ambiguous. It is used for creating a new copy of a UNIX process, and in thread
systems for creating a new thread. To disambiguate, we will always use the
term \UNIX fork" to refer to UNIX's copy process system call.)
UNIX fork
The steps for implementing UNIX fork in the kernel are:
Create and initialize the process control block (PCB) in the kernel
Create a new address space
 
Search WWH ::




Custom Search