One process, several identifiers

A PID namespace provides a process-ID environment. A process can have one PID in its own namespace and another in an ancestor namespace. These identify the same running process; no process is copied merely by giving it another identifier.

The source example on PDF page 18 prints:

ObserverObservation
Original parentOwn PID 10380; child created with PID 10381
Child in the new PID namespaceOwn PID 1; parent PID 0

The first process in the new PID namespace sees itself as PID 1. Its actual parent is outside that namespace and has no PID visible within it, so getppid() returns 0. The child was not created without a parent.

Visibility and permissions

Processes can be visible from ancestor PID namespaces; the child namespace does not get the parent’s complete process view. Sibling PID namespaces do not acquire visibility of one another’s processes merely because both share a host.

The host can identify the child using PID 10381. If an authorized caller terminates that process, the same process that calls itself PID 1 terminates. Visibility does not by itself grant permission to signal or trace a process. Namespace ancestry is also distinct from being the actual parent process.

Read the C example

clone(child_fn, child_stack + sizeof(child_stack),
      CLONE_NEWPID | SIGCHLD, NULL);
PartMeaning
cloneCreate a child, with flags controlling sharing and namespace creation
child_fnFunction the child starts executing
child_stack + sizeof(child_stack)End of the supplied stack storage in this example
CLONE_NEWPIDCreate the child in a new PID namespace
SIGCHLDRequest the usual child-termination notification

getpid() reads the caller’s PID, getppid() its visible parent PID, and the parent uses waitpid(child_pid, ...) to wait for the child it created. PID numbers and output ordering are example observations, not fixed values for another run. Error handling and full C implementation details were not exercised.

On PDF page 17, struct upid pairs a numerical PID with a namespace; the shown struct pid holds namespace-level identifiers. This supports the mental model that the number must be interpreted with its namespace. The kernel layout is a source snapshot, not an API to memorize as immutable.

A PID namespace is not a whole container

Creating only CLONE_NEWPID does not provide separate mounts, networking, users or cgroup limits. A correctly configured process-listing environment also needs an appropriate /proc mount; a runtime combines mechanisms rather than relying on the PID flag alone.

Retrieval practice

The host sees PID 7000; the process sees PID 1. Are these separate processes? No. Terminating the host-identified process terminates the same execution context.

Why can two environments both have PID 1? PID identity is scoped to the namespace; the host can distinguish their underlying processes.

Is PID 1 automatically host administrator? No. PID identification is not a grant of host-wide privilege.

Lecture 06 - Lightweight Virtualization - Cgroups and Namespaces, PDF pages 14-18. Added qualifications distinguish namespace ancestry, permissions and complete process-view setup. Linux PID namespace manual.