cgroup_namespaces(7)
โจ NAME โจ
cgroup_namespaces โ the lowkey iconic overview of Linux cgroup namespaces ๐
(this is the section 7 page, from the Miscellaneous Information Manual, bestie, and yes we're doing the whole thing)
๐ฆ DESCRIPTION ๐ฆ
Okay so first things first: if you want the big-picture lore on namespaces in general, go read namespaces(7). This page is specifically about the cgroup flavor.
Cgroup namespaces virtualize the view of a process's cgroups (peep cgroups(7) for that one) as seen via /proc/pid/cgroup and /proc/pid/mountinfo. Like, the cgroups are still there, you're just seeing them through a cute lil lens. ๐ธ
Every cgroup namespace has its own set of cgroup root directories. Those root directories are the base points for the relative locations that get displayed in the corresponding records over in the /proc/pid/cgroup file. So when a process makes a new cgroup namespace by using clone(2) or unshare(2) with the CLONE_NEWCGROUP flag, its current cgroups directories become the cgroup root directories of the new namespace. (And no cap, this applies both for the cgroups version 1 hierarchies and the cgroups version 2 unified hierarchy. Equal opportunity fr fr.)
Now, when you're reading the cgroup memberships of a "target" process from /proc/pid/cgroup, the pathname shown in the third field of each record will be relative to the reading process's root directory for the corresponding cgroup hierarchy. And if the cgroup directory of the target process lies outside the root directory of the reading process's cgroup namespace? Then the pathname will show ../ entries for each ancestor level in the cgroup hierarchy. It's giving "climb up out of here." ๐ช
The following shell session demonstrates the effect of creating a new cgroup namespace. Grab a snack, this is a whole saga and it slays.
First, (as superuser ๐ฅ) in a shell in the initial cgroup namespace, we create a child cgroup in the freezer hierarchy, and place a process in that cgroup that we will use as part of the demonstration below:
# mkdir -p /sys/fs/cgroup/freezer/sub2;
# sleep 10000 & # Create a process that lives for a while
[1] 20124
# echo 20124 > /sys/fs/cgroup/freezer/sub2/cgroup.procs;
We then create another child cgroup in the freezer hierarchy and put the shell into that cgroup:
# mkdir -p /sys/fs/cgroup/freezer/sub;
# echo $$; # Show PID of this shell
30655
# echo 30655 > /sys/fs/cgroup/freezer/sub/cgroup.procs;
# cat /proc/self/cgroup | grep freezer;
7:freezer:/sub
Next, we use unshare(1) to create a process running a new shell in new cgroup and mount namespaces:
# PS1='sh2# ' unshare -Cm bash;
From the new shell started by unshare(1), we then inspect the /proc/pid/cgroup files of, respectively, the new shell, a process that is in the initial cgroup namespace (init, with PID 1), and the process in the sibling cgroup (sub2):
sh2# cat /proc/self/cgroup | grep freezer;
7:freezer:/
sh2# cat /proc/1/cgroup | grep freezer;
7:freezer:/..
sh2# cat /proc/20124/cgroup | grep freezer;
7:freezer:/../sub2
From the output of the first command, we see that the freezer cgroup membership of the new shell (which is in the same cgroup as the initial shell) is shown defined relative to the freezer cgroup root directory that was established when the new cgroup namespace was created. (In absolute terms, the new shell is in the /sub freezer cgroup, and the root directory of the freezer cgroup hierarchy in the new cgroup namespace is also /sub. Thus, the new shell's cgroup membership is displayed as /.) Iconic behavior honestly. ๐
However โ and this is the plot twist ๐ญ โ when we look in /proc/self/mountinfo we see the following anomaly:
sh2# cat /proc/self/mountinfo | grep freezer;
155 145 0:32 /.. /sys/fs/cgroup/freezer ...
The fourth field of this line (/..) should show the directory in the cgroup filesystem which forms the root of this mount. Since by the definition of cgroup namespaces, the process's current freezer cgroup directory became its root freezer cgroup directory, we should see / in this field. The problem here is that we are seeing a mount entry for the cgroup filesystem corresponding to the initial cgroup namespace (whose cgroup filesystem is indeed rooted at the parent directory of sub). To fix this problem, we must remount the freezer cgroup filesystem from the new shell (i.e., perform the mount from a process that is in the new cgroup namespace), after which we see the expected results:
sh2# mount --make-rslave /; # Don't propagate mount events
# to other namespaces
sh2# umount /sys/fs/cgroup/freezer;
sh2# mount -t cgroup -o freezer freezer /sys/fs/cgroup/freezer;
sh2# cat /proc/self/mountinfo | grep freezer;
155 145 0:32 / /sys/fs/cgroup/freezer rw,relatime ...
There it is. The /. We love to see it. ๐
๐ STANDARDS ๐
Linux.
๐ NOTES ๐
Use of cgroup namespaces requires a kernel that is configured with the CONFIG_CGROUPS option. No option, no namespace, no vibes. Configure accordingly bestie.
The virtualization provided by cgroup namespaces serves a number of purposes, and honestly each one ate:
- It prevents information leaks whereby cgroup directory paths outside of a container would otherwise be visible to processes in the container. Such leakages could, for example, reveal information about the container framework to containerized applications. ๐
- It eases tasks such as container migration. The virtualization provided by cgroup namespaces allows containers to be isolated from knowledge of the pathnames of ancestor cgroups. Without such isolation, the full cgroup pathnames (displayed in
/proc/self/cgroups) would need to be replicated on the target system when migrating a container; those pathnames would also need to be unique, so that they don't conflict with other pathnames on the target system. - It allows better confinement of containerized processes, because it is possible to mount the container's cgroup filesystems such that the container processes can't gain access to ancestor cgroup directories. Consider, for example, the following scenario:
- We have a cgroup directory,
/cg/1, that is owned by user ID 9000. - We have a process, X, also owned by user ID 9000, that is namespaced under the cgroup
/cg/1/2(i.e., X was placed in a new cgroup namespace viaclone(2)orunshare(2)with theCLONE_NEWCGROUPflag).
- We have a cgroup directory,
In the absence of cgroup namespacing, because the cgroup directory /cg/1 is owned (and writable) by UID 9000 and process X is also owned by user ID 9000, process X would be able to modify the contents of cgroups files (i.e., change cgroup settings) not only in /cg/1/2 but also in the ancestor cgroup directory /cg/1. Namespacing process X under the cgroup directory /cg/1/2, in combination with suitable mount operations for the cgroup filesystem (as shown above), prevents it modifying files in /cg/1, since it cannot even see the contents of that directory (or of further removed cgroup ancestor directories). Combined with correct enforcement of hierarchical limits, this prevents process X from escaping the limits imposed by ancestor cgroups. Not process X trying to sneak out. Not on our watch. ๐ซโจ
Okay real talk for one sec: that last bullet is the whole point of the confinement game. Process X can't touch what it can't see. Stay in your lane, X. ๐
๐ SEE ALSO ๐
unshare(1), clone(2), setns(2), unshare(2), proc(5), cgroups(7), credentials(7), namespaces(7), user_namespaces(7)
aaaand that's the page bestie!! ๐ซถ this was Linux man-pages 6.20, dated 2026-02-08, and yes it's cgroup_namespaces(7) โ go forth and namespace responsibly, ily, 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 2016, Michael Kerrisk <mtk.manpages@gmail.com>
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms