forgejo-runner-optimiser/docs/background/identify-process-cgroup-by-pid.md

39 lines
760 B
Markdown
Raw Permalink Normal View History

2026-02-09 17:24:57 +01:00
# Identifying a Process's Cgroup by PID
2026-02-09 17:24:57 +01:00
Read `/proc/<PID>/cgroup` to find which cgroup (and therefore which container) a process belongs to.
2026-02-09 17:24:57 +01:00
## /proc/PID/cgroup
```bash
cat /proc/<PID>/cgroup
```
2026-02-09 17:24:57 +01:00
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
```
2026-02-09 17:24:57 +01:00
On cgroup v2, the path after `::` is the cgroup path under `/sys/fs/cgroup/`.
## Other Methods
```bash
2026-02-09 17:24:57 +01:00
# ps format options
ps -o pid,cgroup -p <PID>
2026-02-09 17:24:57 +01:00
# systemd systems
systemd-cgls --unit <unit-name>
2026-02-09 17:24:57 +01:00
systemd-cgls # whole tree
```
2026-02-09 17:24:57 +01:00
## Quick One-Liners
```bash
2026-02-09 17:24:57 +01:00
cat /proc/self/cgroup # current shell
cat /proc/$$/cgroup # also current shell
cat /proc/1234/cgroup # specific PID
```