Skip to main content

parse_cgroup

Function parse_cgroup 

Source
pub fn parse_cgroup(content: &str) -> Option<String>
Expand description

Parse a container runtime out of /proc/<pid>/cgroup content. Pure so it tests against captured cgroup strings — no /proc required.

cgroup v2 puts the whole hierarchy on one 0::<path> line; v1 has many id:ctrl:path lines. We scan every line’s path for a runtime’s signature scope/dir name, because the signature can sit at any depth (systemd slices nest it under system.slice, kubelet under kubepods.slice/kubepods-besteffort.slice/...). The first runtime we recognize wins.

Returns a short, stable label (docker:<12 hex>, k8s:<12>, podman:<12>, lxc:<name>) or None for a host process. We deliberately do NOT invent an id when none is parseable (bare kubepods with no pod id → k8s:?): a truncated id presented as exact would be a quiet lie, and matching the wrong pod is worse than admitting we only know “some pod”.