Of the six typical cases mentioned earlier in the section
"The Process's Address
Space," in which a process gets new memory regions, the first
fork( ) system
call—requires the creation of a whole new address space for the child
process. Conversely, when a process terminates, the kernel destroys its
address space. In this section, we discuss how these two activities are
performed by Linux.
In the section "The clone( ), fork( ), and
vfork( ) System Calls" in Chapter 3, we mentioned that the
kernel invokes the
function while creating a new process. This function creates the process
address space by setting up all Page Tables and memory descriptors of
the new process.
Each process usually has its own address space, but lightweight
processes can be created by calling
) with the
set. These processes share the same address space; that is, they are
allowed to address the same set of pages.
Following the COW approach described earlier, traditional processes inherit the address space of their parent: pages stay shared as long as they are only read. When one of the processes attempts to write one of them, however, the page is duplicated; after some time, a forked process usually gets its own address space that is different from that of the parent process. Lightweight processes, on the other hand, use the address space of their parent process. Linux implements them simply ...