Linux Kernel Architecture

(Jacob Rumans) #1

Chapter 2: Process Management and Scheduling


res_abc

res_def
count = m

count = m

task_struct(parent) task_struct(child)

CLONE_ABC !CLONE_ABC

count = 1

count = n count = n+ 1

Figure 2-10: When a new thread is created, resources of the parent can either be shared or copied.

Deciding if a resource can be cloned or must be copied is done through numerous helper routines — one
for each resource. It is not my intention here to discuss the (rather uninteresting) implementations of the
variouscopy_xyzfunctions, but I summarize their effects below. I will introduce the data structures asso-
ciated with every process component when I discuss the respective subsystem in detail in the following
chapters.


❑ copy_semundouses the System V semaphores of the parent process ifCOPY_SYSVSEMis set (see
Chapter 5).
❑ copy_filesuses the file descriptors of the parent process ifCLONE_FILESis set. Otherwise, a new
filesstructure is generated (see Chapter 8) that contains the same information as the parent
process. This information can be modified independently of the original structure.
❑ copy_fsuses the filesystem context (task_struct->fs) of the parent process ifCLONE_FSis set.
This is anfs_structtype structure that holds, for example, the root directory and the current
working directory of the process (see Chapter 8 for detailed information).
❑ copy_sighanduses the signal handlers of the parent process (task_struct->sighand)if
CLONE_SIGHANDorCLONE_THREADis set. Chapter 5 discusses thestruct sighand_struct
structure used in more detail.
❑ copy_signaluses the non-handler-specific part of signal handling (task_struct->signal,see
Chapter 5) together with the parent process ifCLONE_THREADis set.
❑ copy_mmcauses the parent process and child process to share the same address space ifCOPY_MM
is set. In this case, both processes use the same instance ofmm_struct(see Chapter 4) to which
task_struct->mmpoints.
Ifcopy_mmisnotset, it does not mean that the entire address space of the parent process is
copied. The kernel does, in fact, create a copy of the page tables but does not copy the actual
contents of the pages. This is done using the COW mechanism only if one of the two processes
writes to one of the pages.
❑ copy_namespaceshas special call semantics. It is used to set up namespaces for the child
process. Recall that severalCLONE_NEWxyzflags control which namespaces aresharedwith the
Free download pdf