$_ CLI In Depth
Learning progress 0%
lesson syscalls namespaces cgroups

Namespaces: PID, Mount, UTS & Net

5 min read Module 17: Syscalls, Namespaces & cgroups Updated Dec 5, 2026
Cheat Sheet
0:00 / 3:19

Global resources and private views

On a Linux system some resources exist once for the whole machine: the process table, the mount table, the host name, the network stack, the list of inter-process communication queues, and the user and group IDs. Namespaces wrap one of these resources so that a set of processes sees a private copy. The kernel gives each process a pointer to its namespace set, and system calls that look up process IDs, mounts, or interfaces consult that pointer.

Namespaces are the isolation half of a container. They hide things. A container cannot see the host's process list, cannot mount over the host's files, and cannot see the host's network interfaces, because each of those views belongs to its own namespace. The other half is cgroups, which limit how much a group of processes may use.

The main namespace types

Linux has several namespace types, each named after what it isolates. The most common are these:

  • mnt isolates the mount table, so mounts made inside the namespace are not seen outside it.
  • pid gives processes their own numbering, and the first process in a new PID namespace is PID 1 inside it.
  • uts isolates the host name and the domain name.
  • net gives its own network interfaces, routing tables, and firewall rules.
  • ipc isolates System V message queues and shared memory names.
  • user maps user and group IDs, so a process can be root inside a namespace without being root outside.
  • cgroup virtualizes the view of the cgroup hierarchy.

The man page namespaces(7) is the reference for the whole list and for how each one behaves.

Seeing your namespaces

The directory /proc/PID/ns contains one link per namespace type. Each link has a target of the form type:[inode], where the number is the inode of the namespace object. Two processes that are in the same namespace show the same number for that type. Changing namespace means the link changes to a different number.

BASH1 lines
ls -l /proc/self/ns

The output lists links such as mnt -> mnt:[4026531841]. The exact numbers are not important. What matters is that they exist, and that a separate command can read them and compare them. Some kernels show more entries, such as time or cgroup, and the lab kernel may show a subset.

BASH1 lines
readlink /proc/self/ns/uts

This prints one identifier, which names the UTS namespace of the shell that runs the command. A process that starts a new UTS namespace gets a different identifier, and its host name can change without affecting the rest of the system.

Comparing namespaces

Namespace identifiers are useful for answering a simple question: are two processes isolated from each other? If the net link of two processes has the same number, they share a network stack. If the pid numbers differ, one of them is in a separate PID view. Scripts can compare the identifiers with a plain string comparison.

Because inode numbers are assigned by the kernel and change on every boot, do not write them into a file that will be read later. Compare them while both values are current.

Tip

Namespace identifiers answer "same or different". They do not tell you what the namespace contains. For the contents, read the process's own status, mount table, and interfaces from inside the namespace.

Who creates namespaces

A process creates a namespace with the unshare system call or a clone flag such as CLONE_NEWPID, and it joins an existing one with setns. The next lesson uses the unshare and nsenter programs, which wrap those calls. Creating most namespaces needs privilege, and some kernels allow unprivileged users to create user namespaces, which then grant the rest. Whether this lab kernel allows that is something you will check directly.

Namespaces stay alive as long as at least one process is in them, even if the creating process has exited. This is why a container can keep running a shell after its init has exited, and why stale namespaces sometimes show up in /proc.

Nested PID namespaces

PID namespaces nest. A process in a child PID namespace has one PID in its own namespace and a different PID in each ancestor namespace, and the host sees the number from the outermost view. The process list from the host therefore shows every process, while the list from inside a container shows only the processes in that container, with small numbers starting from one. A tool that prints PIDs must say which view it is using, because the same process can have two numbers.

The other namespace types work differently. A mount table or a network interface belongs to exactly one namespace at a time, and moving an interface between namespaces is an explicit operation. Reading the namespace link tells you which namespace a process is in right now, and that is the only question the link answers.

Why the links help when debugging

When a tool reports one network interface and you see another, compare the net links of the tool and of your shell. A mismatch means the tool runs in a different network namespace, and the fix is to run it inside the namespace where the interface lives. The comparison takes seconds and avoids guesses about firewalls or routing tables.

A common mistake with inode numbers

Some people try to identify a namespace by its number and expect the same number to appear after a reboot. The kernel assigns each namespace an inode number from an internal pool, so the number has no meaning across boots. The number is only useful for comparing live processes, and that is the use the lab makes of it. Treat a saved listing as a snapshot of one moment, and read the links again before you compare them.

What a container really is: namespaces, cgroups and a root

Visualizer

A container is not a special kind of object. It is ordinary processes inside namespaces that limit what they can see, cgroups that limit what they can use, and a root directory of their own.

1 / 4
ls -l /proc/PID/ns, one link per namespace (inode numbers are examples)
cgroupcgroup:[4026531835]
ipcipc:[4026531839]
mntmnt:[4026531841]
netnet:[4026531840]
pidpid:[4026531836]
useruser:[4026531837]
utsuts:[4026531838]

Each process points at one namespace of each kind. Two processes with the same inode number share that namespace. This shell uses the default, host-wide ones.

ls -l /proc/$$/ns
Terminal lab · 3 steps · real Linux in your browser

Look at namespaces through /proc/PID/ns

List the namespace links of your shell and compare their identifiers.

01
List the namespace links
Each entry in /proc/PID/ns is a link. The target has the form type:[inode], where the inode number identifies one namespace instance. Save the list for your process: ``bash ls -l /proc/self/ns > namespaces.txt `` Open namespaces.txt. You should see entries for mnt, uts, net, and pid.
Show hint for step 1
The inode number is what matters for comparing namespaces. Two processes in the same namespace show the same number.
02
Read one namespace link
readlink prints the target of a single link. Save the UTS namespace identifier of your shell: ``bash readlink /proc/self/ns/uts > uts.txt `` Open uts.txt. It should look like uts:[ followed by digits and ].
Show hint for step 2
Use the path /proc/self/ns/uts. The output has no spaces.
03
Build a table of all namespaces
Loop over every entry in /proc/self/ns and write one line per namespace with its name and its identifier: ``bash for ns in /proc/self/ns/*; do printf "%s %s\n" "$(basename "$ns")" "$(readlink "$ns")" done > all.txt `` Open all.txt. It should have at least four lines.
Show hint for step 3
basename strips the directory part from each path. The printf format puts the name, a space, and the target on each line.
Check yourself Question 1 of 4
Concept Check Namespace for host names recall

Which namespace type isolates the host name and the domain name?

Recap & Key Takeaways

A namespace gives a set of processes a private view of one global resource, such as process IDs, mounts, host name, or network interfaces.
The seven common namespace types are mnt, pid, uts, net, ipc, user, and cgroup, and each is documented in namespaces(7).
ls -l /proc/PID/ns shows one link per namespace, and matching identifiers mean two processes share that namespace.
Namespaces are isolation and cgroups are limits, and a container is built from both.
Was this lesson helpful? Spot an issue or have a suggestion? Let us know on GitHub.
Report an issue