Implementation ofdofork

All three fork mechanisms end up in do_fork in kernel/fork.c (an architecture-independent function), whose code flow diagram is shown in Figure 2-7.

do_fork begins with an invocation of copy_process, which performs the actual work of generating a new process and reusing the parent process data specified by the flags. Once the child process has been generated, the kernel must carry out the following concluding operations:

Figure 2-7: Code flow diagram for do_fork.

□ Since fork returns the PID of the new task, it must be obtained. This is complicated because the fork operation could have opened a new PID namespace if the flag clone_newpid was set. If this is the case, then task_pid_nr_ns is required to obtain the PID that was selected for the new process in the parent namespace, that is, the namespace of the process that issued fork.

If the PID namespace remains unchanged, calling task_pid_vnr is enough to obtain the local PID because old and new processes will live in the same namespace.

Continue reading here: Kernelforkc

Was this article helpful?

0 0