Chapter 2: Process Management and Scheduling
Exiting Processes
Indo_forkthe bulk of the work is done by thecopy_processfunction, whose code flow diagram is
shown in Figure 2-8. Notice that the function has to handle the main work for the three system callsfork,
vfork,andclone.
Check resource limits
Check flags
copy_process
dup_task_struct
sched_fork
copy_semundo
copy_files
copy_fs
copy_sighand
copy_signal
copy_mm
copy_namespaces
copy_thread
Initialize task structure
Copy/share process components
Set IDs, task relationships, etc.
Figure 2-8: Code flow diagram forcopy_process.
Because the kernel has to deal with a large number of special and very specific situations, let’s restrict our
description to a slightly simplified version of the function so as not to lose sight of the most important
aspects in a myriad of details.
Quite a number of flags control the behavior of process duplication. They are all well documented in
theclone(2)man page, and instead of repeating them here, I advise you to just take a look into it — or,
for that matter, any good text on Linux systems programming. More interesting is that there are some
flag combinations that do not make sense, and the kernel has to catch these. For instance, it does not
make sense to request creation of a new namespace (CLONE_NEWNS), on the one hand, but also express the