Chapter 2: Process Management and Scheduling
...
int level;
struct pid_namespace *parent;
};
In reality, the structure also contains elements that are needed by the PID allocator to produce a stream
of unique IDs, but these do not concern us now. What is interesting are the following elements:
❑ Every PID namespace is equipped with a task that assumes the role taken byinitin the global
picture. One of the purposes ofinitis to callwait4for orphaned tasks, and this must likewise
be done by the namespace-specificinitvariant. A pointer to the task structure of this task is
stored inchild_reaper.
❑ parentis a pointer to the parent namespace, andleveldenotes the depth in the namespace hier-
archy. The initial namespace has level 0, any children of this namespace are in level 1, children
of children are in level 2, and so on. Counting the levels is important because IDs in higher levels
must be visible in lower levels. From a given level setting, the kernel can infer how many IDs
must be associated with a task.
Recall from Figure 2-3 that namespaces are hierarchically related. This clarifies the above definitions.
PID management is centered around two data structures:struct pidis the kernel-internal representation
of a PID, andstruct upidrepresents the information that is visible in a specific namespace. The definition
of both structures is as follows:
<pid.h>
struct upid {
int nr;
struct pid_namespace *ns;
struct hlist_node pid_chain;
};
struct pid
{
atomic_t count;
/* lists of tasks that use this pid */
struct hlist_head tasks[PIDTYPE_MAX];
int level;
struct upid numbers[1];
};
Since these and some other data structures are comprehensively interconnected, Figure 2-5 provides an
overview about the situation before I discuss the individual components.
As forstruct upid,nrrepresents the numerical value of an ID, andnsis a pointer to the namespace to
which the value belongs. Allupidinstances are kept on a hash table to which we will come in a moment,
andpid_chainallows for implementing hash overflow lists with standard methods of the kernel.
The definition ofstruct pidis headed by a reference countercount.tasksis an array with a hash
list head for every ID type. This is necessary because an ID can be used for several processes. All
task_structinstances that share a given ID are linked on this list.PIDTYPE_MAXdenotes the number of
ID types: