# info > CGROUP_NAMESPACES

---
type: CommandReference
command: cgroup_namespaces
mode: man
section: 7
source: man-pages
---

## Quick Reference

- `CLONE_NEWCGROUP` — flag for `clone(2)` and `unshare(2)` to create a new cgroup namespace
- `unshare -Cm` — create a new shell in new cgroup and mount namespaces
- `/proc/[pid]/cgroup` — shows cgroup membership; paths are relative to the reader's cgroup namespace root
- `/proc/[pid]/mountinfo` — shows mount info; may require remount after creating namespace
- Cgroup namespaces virtualize the view of cgroups, preventing information leaks, easing container migration, and improving confinement

## Name

cgroup_namespaces — overview of Linux cgroup namespaces

## Synopsis

Cgroup namespaces virtualize the view of a process's cgroups as seen via `/proc/[pid]/cgroup` and `/proc/[pid]/mountinfo`. Each namespace has its own set of cgroup root directories. When a new namespace is created with `CLONE_NEWCGROUP`, the current cgroups directories become the root directories of the new namespace. Namespaces are a Linux-specific feature.

## Examples

The following shell session demonstrates the effect of creating a new cgroup namespace (requires `CONFIG_CGROUPS`):

shell
# As superuser, in initial cgroup namespace:
mkdir -p /sys/fs/cgroup/freezer/sub2
sleep 10000 &
echo $! > /sys/fs/cgroup/freezer/sub2/cgroup.procs
mkdir -p /sys/fs/cgroup/freezer/sub
echo $$ > /sys/fs/cgroup/freezer/sub/cgroup.procs
cat /proc/self/cgroup | grep freezer
# Output: 7:freezer:/sub

# Create new cgroup and mount namespaces:
unshare -Cm bash

# Inside new shell:
cat /proc/self/cgroup | grep freezer
# Output: 7:freezer:/
cat /proc/1/cgroup | grep freezer
# Output: 7:freezer:/..
cat /proc/20124/cgroup | grep freezer
# Output: 7:freezer:/../sub2

# Remount cgroup filesystem to fix mountinfo:
mount --make-rslave /
umount /sys/fs/cgroup/freezer
mount -t cgroup -o freezer freezer /sys/fs/cgroup/freezer
cat /proc/self/mountinfo | grep freezer
# Output: 155 145 0:32 / /sys/fs/cgroup/freezer rw,relatime ...
## See Also

- [unshare(1)](https://www.chedong.com/phpMan.php/man/unshare/1/markdown)
- [clone(2)](https://www.chedong.com/phpMan.php/man/clone/2/markdown)
- [setns(2)](https://www.chedong.com/phpMan.php/man/setns/2/markdown)
- [unshare(2)](https://www.chedong.com/phpMan.php/man/unshare/2/markdown)
- [proc(5)](https://www.chedong.com/phpMan.php/man/proc/5/markdown)
- [cgroups(7)](https://www.chedong.com/phpMan.php/man/cgroups/7/markdown)
- [credentials(7)](https://www.chedong.com/phpMan.php/man/dentials/7/markdown)
- [namespaces(7)](https://www.chedong.com/phpMan.php/man/namespaces/7/markdown)
- [user_namespaces(7)](https://www.chedong.com/phpMan.php/man/usernamespaces/7/markdown)