Expand description
Linux tracker: one cgroup v2 per agent, under a systemd user scope srv
puts itself in at startup with Delegate=yes, so srv may create and
manage cgroups below it.
A cgroup holds every descendant of what it was given, whatever they do:
setsid, double forks and reparenting don’t leave it (process groups and
sessions can’t hold an agent’s tree: Claude Code and bashwrap each start
new sessions). cgroup.kill ends all of them at once.
See docs/analysis/agent-spawned-process-tracking-2026-10-07.md.
Structs§
- Cgroup
Tracker - One agent’s cgroup.
Functions§
- init
- Move srv into its own delegated systemd user scope
(
agentmux-srv-<pid>.scope). Call once at startup, before any agent spawns. Idempotent; never fails startup. - join_
before_ exec - Make a child join
procs(acgroup.procsfile) before it execs, so it is tracked before it runs any code of its own and before it can fork. - join_
before_ exec_ pty join_before_execfor a PTY spawn (portable-pty has no pre-exec hook): run the command throughsh, which joins and thenexecs it, so the program starts already in the cgroup, as the same process.- root
- The directory per-agent cgroups are created in, once
initsucceeded.