Linux Kernel Architecture

(Jacob Rumans) #1

Chapter 2: Process Management and Scheduling


struct pid_namespace *tmp;
struct upid *upid;
...
tmp = ns;
for (i = ns->level; i >= 0; i--) {
nr = alloc_pidmap(tmp);
...
pid->numbers[i].nr = nr;
pid->numbers[i].ns = tmp;
tmp = tmp->parent;
}
pid->level = ns->level;
...

Starting at the level of the namespace in which the process is created, the kernel goes down to the initial,
global namespace and creates a local PID for each. Allupids that are contained instruct pidare filled
with the newly generated PIDs. Eachupidinstance must be placed on the PID hash:

kernel/pid.c
for (i = ns->level; i >= 0; i--) {
upid = &pid->numbers[i];
hlist_add_head_rcu(&upid->pid_chain,
&pid_hash[pid_hashfn(upid->nr, upid->ns)]);
}
...
return pid;
}

2.3.4 Task Relationships


In addition to the relationships resulting from ID links, the kernel is also responsible for managing the
‘‘family relationships‘‘ established on the basis of theUnixmodel of process creation. The following
terminology is used in this context:

❑ If processAforks to generate processB,Ais known as theparentprocess andBas thechild
process.^6
If processBforks again to create a further processC, the relationship betweenAandCis
sometimes referred to as agrandparentandgrandchildrelationship.
❑ If processAforks several times therefore generating several child processesB 1 ,B 2 ,...,Bn,the
relationship between theBiprocesses is known as asiblingsrelationship.

Figure 2-6 illustrates the possible family relationships graphically.

Thetask_structtask data structure provides two list heads to help implement these relationships:

<sched.h>
struct task_struct {
...
struct list_head children; /* list of my children */

(^6) Unlike natural families, a process has only one parent.

Free download pdf