In this lesson, you will learn how systemd acts as a sophisticated supervisor that tracks and manages the entire lifecycle of a service, rather than just launching it and moving on.
Beyond Simple Process Launching
In earlier init systems, a script would simply start a daemon and lose track of it once the process detached. If that daemon spawned child processes or leaked memory, the system had no way of knowing which sub-processes belonged to that service. systemd changes this by introducing Control Groups (cgroups).
When systemd starts a service, it places that service—and every process it ever creates—into a dedicated cgroup. This allows the init system to treat a service as a single, encapsulated unit. It no longer matters if a daemon forks ten times or creates background workers; systemd maintains a "membership list" of every process associated with that service tree.
Supervision in Action
Because systemd knows exactly which processes belong to a service, it can provide robust supervision:
- Tracking: It monitors the state of all processes in the cgroup. Even if the original parent process crashes,
systemdcan identify and clean up the "leftover" children that would otherwise become orphans or zombies. - Resource Limiting: By using the cgroup boundary, you can restrict a service's CPU or memory usage. If a service exceeds these limits,
systemdcan take action. - Atomic Termination: When you stop a service,
systemddoesn't just send a signal to the parent. It iterates through the entire cgroup tree and sends the termination signal to every process inside, ensuring the service is truly and completely stopped.
You can observe this tree structure yourself by running:
systemd-cgls
This command displays the hierarchy of services and their associated processes. By monitoring this tree, systemd ensures that service management is deterministic, clean, and resistant to "runaway" processes that hide outside the oversight of traditional parent-child process models.
Key Takeaway: By binding services to Linux cgroups, systemd moves beyond simple process execution to full-lifecycle supervision, ensuring that all sub-processes are tracked, contained, and terminated as a single, cohesive unit.