Kernelforkc

task_pid_nr_ns(p, current->nsproxy->pid_ns) : task_pid_vnr(p);

□ If the new process is to be monitored with Ptrace (see Chapter 13), the sigstop signal is sent to the process immediately after generation to allow an attached debugger to examine its data.

□ The child process is woken using wake_up_new_task; in other words, the task structure is added to the scheduler queue. The scheduler also gets a chance to specifically handle newly started tasks, which, for instance, allows for implementing a policy that gives new tasks a good chance to run soon, but also prevents processes that fork over and over again to consume all CPU time.

If a child process begins to run before the parent process, this can greatly reduce copying effort, especially if the child process issues an exec call after fork. However, keep in mind that enqueuing a process in the scheduler data structures does not mean that the child process begins to execute immediately but rather that it is available for selection by the scheduler.

□ If the vfork mechanism was used (the kernel recognizes this by the fact that the clone_vfork flag is set), the completions mechanism of the child process must be enabled. The vfork_done element of the child process task structure is used for this purpose. With the help of the wait_for_completion function, the parent process goes to sleep on this variable until the child process exits. When a process terminates (or a new application is started with execve), the kernel automatically invokes complete(vfork_done). This wakes all processes sleeping on it. In Chapter 14, I discuss the implementation of completions in greater detail.

By adopting this approach, the kernel ensures that the parent process of a child process generated using vfork remains inactive until either the child process exits or a new process is executed. The temporary inactivity of the parent process also ensures that both processes do not interfere with each other or manipulate each other's address space.

Continue reading here: Copying Processes

Was this article helpful?

0 0