| 1 | package cgroup |
| 2 | |
| 3 | import "errors" |
| 4 | |
| 5 | // ErrUnknown is HostProcs saying it cannot tell how many processes a host |
| 6 | // has left: the platform has no cgroup v2 to read (darwin, windows), or the |
| 7 | // agent runs without a delegated subtree, so its exec children share the |
| 8 | // agent's own cgroup and cannot be told apart. A caller records it as "not |
| 9 | // stopped", never as zero (the offline move's source report, Task 3 of |
| 10 | // docs/superpowers/plans/2026-10-20-offline-operator-move.md). |
| 11 | var ErrUnknown = errors.New("cgroup: the host's processes cannot be counted on this box") |
| 12 | |
| 13 | // HostProcs counts the processes left for host on this box: |
| 14 | // |
| 15 | // - in the host's exec cgroup, root/carlos-exec@<host> (ExecName), and |
| 16 | // every cgroup below it (an exec child's sidecar and worker groups); |
| 17 | // - when unit is set, in the cgroup directory unit names and every cgroup |
| 18 | // below it. unit is an absolute path in the cgroup filesystem: for a |
| 19 | // nested row the host's slice, which holds its run, generation, seed, |
| 20 | // sidecar and cmd units alike. |
| 21 | // |
| 22 | // root is the delegated subtree (Manager.Root). A cgroup that does not |
| 23 | // exist holds no process and counts 0. An empty root is ErrUnknown, since |
| 24 | // without delegation the exec children run in the agent's own cgroup. |
| 25 | // Reading never writes, moves or signals anything. |
| 26 | func HostProcs(root, host, unit string) (int, error) { |
| 27 | return hostProcs(root, host, unit) |
| 28 | } |
| 29 | |