namespaces(7)
๐ฆ namespaces(7) โ the manual page, but make it make sense ๐
Miscellaneous Information Manual โจ this is namespaces(7), bestie โ the big overview of Linux namespaces. Buckle up, it's a long one, but it's genuinely iconic.
๐ธ NAME ๐ธ
namespaces โ overview of Linux namespaces. that's the whole vibe.
โจ DESCRIPTION โจ
Okay so picture this: a namespace wraps a global system resource in an abstraction that makes it look to the processes inside the namespace like they've got their very own isolated instance of that global resource. Like a little private world ๐โจ
Changes to the global resource are visible to other processes that are members of the namespace, but they're invisible to other processes. One use of namespaces โ and honestly the main character use โ is to implement containers. ๐ซถ
This page gives you the pointers to info on the various namespace types, describes the associated /proc files, and summarizes the APIs for working with namespaces. iykyk.
๐ Namespace types ๐
Here's the lineup of namespace types available on Linux. The second column is the flag value used to specify the namespace type in various APIs. The third column points you at the manual page with the deets. The last column is a lil summary of the resources that get isolated by that namespace type.
- Cgroup โ flag:
CLONE_NEWCGROUPโ page:cgroup_namespaces(7)โ isolates: Cgroup root directory - IPC โ flag:
CLONE_NEWIPCโ page:ipc_namespaces(7)โ isolates: System V IPC, POSIX message queues - Network โ flag:
CLONE_NEWNETโ page:network_namespaces(7)โ isolates: Network devices, stacks, ports, etc. - Mount โ flag:
CLONE_NEWNSโ page:mount_namespaces(7)โ isolates: Mount points - PID โ flag:
CLONE_NEWPIDโ page:pid_namespaces(7)โ isolates: Process IDs - Time โ flag:
CLONE_NEWTIMEโ page:time_namespaces(7)โ isolates: Boot and monotonic clocks - User โ flag:
CLONE_NEWUSERโ page:user_namespaces(7)โ isolates: User and group IDs - UTS โ flag:
CLONE_NEWUTSโ page:uts_namespaces(7)โ isolates: Hostname and NIS domain name
๐ฅ The namespaces API ๐ฅ
So besides the various /proc files described further down, the namespaces API includes these system calls:
clone(2)โ theclone(2)system call creates a new process. If the flags argument of the call specifies one or more of theCLONE_NEW*flags listed above, then new namespaces are created for each flag, and the child process is made a member of those namespaces. (This system call also implements a bunch of features that have literally nothing to do with namespaces, fyi.)setns(2)โ thesetns(2)system call lets the calling process join an existing namespace. The namespace you want to join is specified via a file descriptor that refers to one of the/proc/pid/nsfiles described below.unshare(2)โ theunshare(2)system call moves the calling process to a new namespace. If the flags argument of the call specifies one or more of theCLONE_NEW*flags listed above, then new namespaces are created for each flag, and the calling process is made a member of those namespaces. (This system call also implements a bunch of features unrelated to namespaces too.)ioctl(2)โ variousioctl(2)operations can be used to discover information about namespaces. These operations are described inioctl_nsfs(2).
Creating new namespaces with clone(2) and unshare(2) in most cases requires the CAP_SYS_ADMIN capability, because in the new namespace, the creator will have the power to change global resources that are visible to other processes that are subsequently created in, or join, the namespace. ๐
User namespaces are the exception though โ since Linux 3.8, no privilege is required to create a user namespace. no cap, no cap needed. ๐
๐ฆ The /proc/pid/ns/ directory ๐ฆ
Every process has a /proc/pid/ns/ subdirectory containing one entry for each namespace that supports being manipulated by setns(2):
$ ls -l /proc/$$/ns | awk '{print $1, $9, $10, $11}'
total 0
lrwxrwxrwx. cgroup -> cgroup:[4026531835]
lrwxrwxrwx. ipc -> ipc:[4026531839]
lrwxrwxrwx. mnt -> mnt:[4026531840]
lrwxrwxrwx. net -> net:[4026531969]
lrwxrwxrwx. pid -> pid:[4026531836]
lrwxrwxrwx. pid_for_children -> pid:[4026531834]
lrwxrwxrwx. time -> time:[4026531834]
lrwxrwxrwx. time_for_children -> time:[4026531834]
lrwxrwxrwx. user -> user:[4026531837]
lrwxrwxrwx. uts -> uts:[4026531838]
Bind mounting (see mount(2)) one of the files in this directory to somewhere else in the filesystem keeps the corresponding namespace of the process specified by pid alive even if all processes currently in the namespace terminate. it's giving immortality tbh ๐โจ
Opening one of the files in this directory (or a file that is bind mounted to one of these files) returns a file handle for the corresponding namespace of the process specified by pid. As long as this file descriptor stays open, the namespace stays alive, even if all processes in the namespace terminate. The file descriptor can be passed to setns(2). ๐
In Linux 3.7 and earlier, these files were visible as hard links. Since Linux 3.8, they appear as symbolic links. If two processes are in the same namespace, then the device IDs and inode numbers of their /proc/pid/ns/xxx symbolic links will be the same; an application can check this using the stat.st_dev and stat.st_ino fields returned by stat(2). The content of this symbolic link is a string containing the namespace type and inode number, like this:
$ readlink /proc/$$/ns/uts
uts:[4026531838]
The symbolic links in this subdirectory are as follows:
/proc/pid/ns/cgroup(since Linux 4.6) โ this file is a handle for the cgroup namespace of the process./proc/pid/ns/ipc(since Linux 3.0) โ this file is a handle for the IPC namespace of the process./proc/pid/ns/mnt(since Linux 3.8) โ this file is a handle for the mount namespace of the process./proc/pid/ns/net(since Linux 3.0) โ this file is a handle for the network namespace of the process./proc/pid/ns/pid(since Linux 3.8) โ this file is a handle for the PID namespace of the process. This handle is permanent for the lifetime of the process (i.e., a process's PID namespace membership never changes). periodt./proc/pid/ns/pid_for_children(since Linux 4.12) โ this file is a handle for the PID namespace of child processes created by this process. This can change as a consequence of calls tounshare(2)andsetns(2)(seepid_namespaces(7)), so the file may differ from/proc/pid/ns/pid. The symbolic link gains a value only after the first child process is created in the namespace. (Beforehand,readlink(2)of the symbolic link will return an empty buffer.) ๐ญ rude but true/proc/pid/ns/time(since Linux 5.6) โ this file is a handle for the time namespace of the process./proc/pid/ns/time_for_children(since Linux 5.6) โ this file is a handle for the time namespace of child processes created by this process. This can change as a consequence of calls tounshare(2)andsetns(2)(seetime_namespaces(7)), so the file may differ from/proc/pid/ns/time./proc/pid/ns/user(since Linux 3.8) โ this file is a handle for the user namespace of the process./proc/pid/ns/uts(since Linux 3.0) โ this file is a handle for the UTS namespace of the process.
Permission to dereference or read (readlink(2)) these symbolic links is governed by a ptrace access mode PTRACE_MODE_READ_FSCREDS check; see ptrace(2). ๐
๐ The /proc/sys/user directory ๐
The files in the /proc/sys/user directory (present since Linux 4.9) expose limits on the number of namespaces of various types that can be created. The files are:
max_cgroup_namespacesโ the value in this file defines a per-user limit on the number of cgroup namespaces that may be created in the user namespace.max_ipc_namespacesโ the value in this file defines a per-user limit on the number of ipc namespaces that may be created in the user namespace.max_mnt_namespacesโ the value in this file defines a per-user limit on the number of mount namespaces that may be created in the user namespace.max_net_namespacesโ the value in this file defines a per-user limit on the number of network namespaces that may be created in the user namespace.max_pid_namespacesโ the value in this file defines a per-user limit on the number of PID namespaces that may be created in the user namespace.max_time_namespaces(since Linux 5.7) โ the value in this file defines a per-user limit on the number of time namespaces that may be created in the user namespace.max_user_namespacesโ the value in this file defines a per-user limit on the number of user namespaces that may be created in the user namespace.max_uts_namespacesโ the value in this file defines a per-user limit on the number of uts namespaces that may be created in the user namespace.
Note these details about these files, bestie โ they matter:
- The values in these files are modifiable by privileged processes. ๐
- The values exposed by these files are the limits for the user namespace in which the opening process resides.
- The limits are per-user. Each user in the same user namespace can create namespaces up to the defined limit.
- The limits apply to all users, including UID 0.
- These limits apply in addition to any other per-namespace limits (such as those for PID and user namespaces) that may be enforced.
- Upon encountering these limits,
clone(2)andunshare(2)fail with the errorENOSPC. ๐ - For the initial user namespace, the default value in each of these files is half the limit on the number of threads that may be created (
/proc/sys/kernel/threads-max). In all descendant user namespaces, the default value in each file isMAXINT. - When a namespace is created, the object is also accounted against ancestor namespaces. More precisely:
- Each user namespace has a creator UID.
- When a namespace is created, it is accounted against the creator UIDs in each of the ancestor user namespaces, and the kernel ensures that the corresponding namespace limit for the creator UID in the ancestor namespace is not exceeded. ๐งโโ๏ธ
- And like, the point above? That's the whole reason a fresh user namespace can't be used as a sneaky little escape hatch from the limits that are currently in force in your current user namespace. no loopholes bestie, the vibes are contained ๐
โจ Namespace lifetime โจ
So basically, if nothing else is going on, a namespace justโฆ gets torn down automatically the second the last process inside it terminates or dips out and leaves. Poof. Gone. ๐ซถ
But โ and this is the plot twist โ there are a bunch of other things that can pin a namespace into existence even when it has literally zero member processes. #clingy. Here's the list of what's holding it hostage:
- There's an open file descriptor or a bind mount hanging around for the matching
/proc/pid/ns/*file. ๐ - The namespace is hierarchical (so like, a PID or user namespace) and it's got a child namespace. Family obligations fr fr. ๐ถ
- It's a user namespace that owns one or more nonuser namespaces. She's a landlord. ๐
- It's a PID namespace, and there's a process pointing at it through a
/proc/pid/ns/pid_for_childrensymbolic link. ๐ - It's a time namespace, and there's a process pointing at it through a
/proc/pid/ns/time_for_childrensymbolic link. โฐ - It's an IPC namespace, and a corresponding mount of an
mqueuefilesystem (go readmq_overview(7)๐) refers to this namespace. - It's a PID namespace, and a corresponding mount of a
proc(5)filesystem refers to this namespace. ๐๏ธ
๐ EXAMPLES ๐
Honestly just go look at clone(2) and user_namespaces(7) โ they've got the receipts. โจ
๐ฆ SEE ALSO ๐ฆ
The whole bestie roster, go say hi:
nsenter(1)readlink(1)unshare(1)clone(2)ioctl_nsfs(2)setns(2)unshare(2)proc(5)capabilities(7)cgroup_namespaces(7)cgroups(7)credentials(7)ipc_namespaces(7)network_namespaces(7)pid_namespaces(7)user_namespaces(7)uts_namespaces(7)lsns(8)switch_root(8)
okay that's the whole page bestie, we ATE that. ๐ โจ This lil masterpiece is from Linux man-pages 6.20, dated 2026-02-08 โ going down in history fr fr. now go namespace something responsibly, mwah ๐๐
๐ฆ where this page comes from
- arch rolling: man-pages 6.20-1 ยท BSD-2-Clause AND BSD-3-Clause AND BSD-4.3TAHOE AND BSD-4-Clause-UC AND GPL-1.0-or-later AND GPL-2.0-only AND GPL-2.0-or-later AND GPL-3.0-or-later AND LGPL-3.0-linking-exception AND LGPL-3.0-or-later AND LicenseRef-Public-Domain AND LicenseRef-UltraPermissive AND Linux-man-pages-1-para AND Linux-man-pages-copyleft AND Linux-man-pages-copyleft-2-para AND Linux-man-pages-copyleft-var AND MIT AND Spencer-94
- nixpkgs unstable: man-pages 6.20
- ๐ the page's license: Linux-man-pages-copyleft
- Copyright 2013-2017, Michael Kerrisk <mtk.manpages@gmail.com>
- Copyright 2012, Eric W. Biederman <ebiederm@xmission.com>
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms