|NAMESPACES(7)||Linux Programmer's Manual||NAMESPACES(7)|
This page provides pointers to information on the various namespace types, describes the associated /proc files, and summarizes the APIs for working with namespaces.
|Cgroup||CLONE_NEWCGROUP||cgroup_namespaces(7)||Cgroup root directory|
|IPC||CLONE_NEWIPC||ipc_namespaces(7)||System V IPC, POSIX message queues|
|Network||CLONE_NEWNET||network_namespaces(7)||Network devices, stacks, ports, etc.|
|User||CLONE_NEWUSER||user_namespaces(7)||User and group IDs|
|UTS||CLONE_NEWUTS||uts_namespaces(7)||Hostname and NIS domain name|
Creation of new namespaces using clone(2) and unshare(2) in most cases requires the CAP_SYS_ADMIN capability, since, 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: since Linux 3.8, no privilege is required to create a user namespace.
$ ls -l /proc/$$/ns total 0 lrwxrwxrwx. 1 mtk mtk 0 Apr 28 12:46 cgroup -> cgroup: lrwxrwxrwx. 1 mtk mtk 0 Apr 28 12:46 ipc -> ipc: lrwxrwxrwx. 1 mtk mtk 0 Apr 28 12:46 mnt -> mnt: lrwxrwxrwx. 1 mtk mtk 0 Apr 28 12:46 net -> net: lrwxrwxrwx. 1 mtk mtk 0 Apr 28 12:46 pid -> pid: lrwxrwxrwx. 1 mtk mtk 0 Apr 28 12:46 pid_for_children -> pid: lrwxrwxrwx. 1 mtk mtk 0 Apr 28 12:46 user -> user: lrwxrwxrwx. 1 mtk mtk 0 Apr 28 12:46 uts -> uts:
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.
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 remains open, the namespace will remain 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 as in the following example:
$ readlink /proc/$$/ns/uts uts:
The symbolic links in this subdirectory are as follows:
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).
Note the following details about these files: