The Linux Programming Interface

(nextflipdebug5) #1

PROCESS CREATION


In this and the next three chapters, we look at how a process is created and termi-
nates, and how a process can execute a new program. This chapter covers process
creation. However, before diving into that subject, we present a short overview of
the main system calls covered in these four chapters.

24.1 Overview of fork(), exit(), wait(), and execve()..............................................................


The principal topics of this and the next few chapters are the system calls fork(),
exit(), wait(), and execve(). Each of these system calls has variants, which we’ll also
look at. For now, we provide an overview of these four system calls and how they
are typically used together.

z The fork() system call allows one process, the parent, to create a new process,
the child. This is done by making the new child process an (almost) exact dupli-
cate of the parent: the child obtains copies of the parent’s stack, data, heap,
and text segments (Section 6.3). The term fork derives from the fact that we can
envisage the parent process as dividing to yield two copies of itself.
z The exit(status) library function terminates a process, making all resources
(memory, open file descriptors, and so on) used by the process available for
subsequent reallocation by the kernel. The status argument is an integer that
determines the termination status for the process. Using the wait() system call,
the parent can retrieve this status.
Free download pdf