CGroups
Powered by systemd System and Service Manager.
Hierarchy
Networks, nodes and commands are forming a Unified Cgroup Hierarchy (v2):
$ systemd-cgls
...
├─gont.slice
│ └─gont-barlow.slice
│ └─gont-barlow-h1.slice
│ └─gont-run-2797869.scope
│ └─2797869 sleep 3600
We rely on systemd's service manager to manage the hierarchy.
Freeze, Thaw, Kill
All processes of a Cgroup can be controlled together:
cmd.Freeze() // Suspends all processes, included forked sub-processes
cmd.Thaw() // Resumes all processes
cmd.Teardown() // Sends a SIGKILL to all processes
This also works on the host and network levels.
By default, Close()
will invoke Teardown()
.
Hence, guaranteeing that no lingering processes will stick around.
Resource Control
We can control resource quota's in each level of the hierarchy using systemd resource control properties:
import sdopt "github.com/cunicu/gont/v2/options/systemd"
network, _ := gont.NewNetwork("mynet", sdopt.AllowedCPUs(0b1100))
host1, _ := network.AddHost("host1", sdopt.TasksMax(10))
cmd := host1.Command("long-running-command", sdopt.RuntimeMax(10 * time.Second))
cmd := host1.Command("memory-hungry-command", sdopt.MemoryMax(1 << 20))