Copying Processes

In do_fork the bulk of the work is done by the copy_process function, whose code flow diagram is shown in Figure 2-8. Notice that the function has to handle the main work for the three system calls fork, vfork, and clone.

Figure 2-8: Code flow diagram for copy_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 the clone(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 desire to share all filesystem information with the parent (clone_fs). It's not complicated to catch this combination and return an error code:

Continue reading here: Kernelforkc

Was this article helpful?

0 0