38 lines
760 B
Markdown
38 lines
760 B
Markdown
# Identifying a Process's Cgroup by PID
|
|
|
|
Read `/proc/<PID>/cgroup` to find which cgroup (and therefore which container) a process belongs to.
|
|
|
|
## /proc/PID/cgroup
|
|
|
|
```bash
|
|
cat /proc/<PID>/cgroup
|
|
```
|
|
|
|
Shows all cgroup controllers the process belongs to:
|
|
```
|
|
12:blkio:/user.slice
|
|
11:memory:/user.slice/user-1000.slice
|
|
...
|
|
0::/user.slice/user-1000.slice/session-1.scope
|
|
```
|
|
|
|
On cgroup v2, the path after `::` is the cgroup path under `/sys/fs/cgroup/`.
|
|
|
|
## Other Methods
|
|
|
|
```bash
|
|
# ps format options
|
|
ps -o pid,cgroup -p <PID>
|
|
|
|
# systemd systems
|
|
systemd-cgls --unit <unit-name>
|
|
systemd-cgls # whole tree
|
|
```
|
|
|
|
## Quick One-Liners
|
|
|
|
```bash
|
|
cat /proc/self/cgroup # current shell
|
|
cat /proc/$$/cgroup # also current shell
|
|
cat /proc/1234/cgroup # specific PID
|
|
```
|