Interview Prep/Linux/Processes, Signals & systemd

How does systemd track a service's processes, even if they fork?

AdvancedConceptProcesses, Signals & systemd
Answer

Every service gets its own cgroup (/sys/fs/cgroup/system.slice/nginx.service/). All children stay in that cgroup no matter how many times they fork or daemonize, so systemctl stop can kill all of them (KillMode=control-group, the default). That is also how resource limits like MemoryMax= apply to the whole service.

systemd-cgls -u nginx.service
systemctl status nginx    # the CGroup: tree
All Linux questions Roadmap: Linux

More on Processes, Signals & systemd