Process Identifiers

Each process is, however, not only characterized by its PID but also by other identifiers. Several types are possible:

□ All processes in a thread group (i.e., different execution contexts of a process created by calling clone with clone_thread as we will see below) have a uniform thread group id (TGID). If a process does not use threads, its PID and TGID are identical.

The main process in a thread group is called the group leader. The group_leader element of the task structures of all cloned threads points to the task_struct instance of the group leader.

□ Otherwise, independent processes can be combined into a process group (using the setpgrp system call). The pgrp elements of their task structures all have the same value, namely, the PID of the process group leader. Process groups facilitate the sending of signals to all members of the group, which is helpful for various system programming applications (see the literature on system programming, e.g., [SR05]). Notice that processes connected with pipes are contained in a process group.

□ Several process groups can be combined in a session. All processes in a session have the same session ID which is held in the session element of the task structure. The SID can be set using the setsid system call. It is used in terminal programming but is of no particular relevance to us here.

Namespaces add some additional complexity to how PIDs are managed. Recall that PID namespaces are organized in a hierarchy. When a new namespace is created, all PIDs that are used in this namespace are visible to the parent namespace, but the child namespace does not see PIDs of the parent namespace. However this implies that some tasks are equipped with more than one PID, namely, one per namespace they are visible in. This must be reflected in the data structures. We have to distinguish between local and global IDs:

□ Global IDs are identification numbers that are valid within the kernel itself and in the initial namespace to which the init tasks started during boot belongs. For each ID type, a given global identifier is guaranteed to be unique in the whole system.

□ Local IDs belong to a specific namespace and are not globally valid. For each ID type, they are valid within the namespace to which they belong, but identifiers of identical type may appear with the same ID number in a different namespace.

The global PID and TGID are directly stored in the task struct, namely, in the elements pid and tgid:

Continue reading here: Info

Was this article helpful?

0 0