﻿# Terminate model workers with their service control group

Use the unit control group and kill procedure to define worker cleanup rather than assuming main-process exit ends the workload.

Author: Retrivium editorial team
Updated: 2026-11-03
Canonical URL: https://retrivium.ai/journal/guide-linux-systemd-killmode/
Language: en

Stopping a model service removes its supervisor, but GPU workers remain and hold resources. A process tree is not the same boundary as a systemd service's control group. Read KillMode and the actual membership before assuming that terminating the familiar main PID necessarily stops every process belonging to the workload.

## Inventory service membership

Associate the unit with its control group and inspect its remaining processes through authorized status. Preserve instance and invocation identity. A child can outlive its original parent, so a tree rooted only at the current supervisor can miss it. Conversely, a similar process name does not establish membership in this particular unit.

## Read the selected kill scope

control-group targets remaining processes in the unit, while mixed treats the main process and later remaining group differently. process targets only the main process, and none leaves termination to another arrangement. These choices define lifecycle ownership, not merely signal preference. Review the actual unit and installed behavior rather than inferring scope from the presence of an ExecStop command.

## Preserve the stop sequence

ExecStop can run before the manager's configured killing procedure. A command that only sends an asynchronous request may finish before workers drain. Read TimeoutStopSec, the initial signal and final-kill policy together. Keep application shutdown milestones distinct from the manager's decision to terminate remaining processes after the applicable boundary.

## Avoid accidental orphan capacity

A stopped unit with leftover workers can retain sockets, GPU memory and files, then conflict with a new start. Disabling final killing does not itself create safe graceful completion. Inspect restart behavior when old processes remain. Do not terminate arbitrary processes by executable name; identify ownership so another service's legitimate worker is not swept into the correction.

## Exercise the complete group

Use a disposable supervisor with harmless children, including one slow to stop. Observe main-process exit, child cleanup, timeout and subsequent restart under the intended policy. Acceptance means every owned process has a defined lifecycle and resources are released as expected. It does not guarantee that long inference streams finish, external writes roll back or every application reacts correctly to the first signal.

## Primary references

[systemd Service Termination](https://www.freedesktop.org/software/systemd/man/latest/systemd.kill.html).

[systemd Service Configuration](https://www.freedesktop.org/software/systemd/man/latest/systemd.service.html).

[Linux Control Group v2](https://docs.kernel.org/admin-guide/cgroup-v2.html).

Related reading: [Graceful inference-server termination with active streams](/journal/provider-graceful-termination-active-streams/); [Cannot create thread in a container: checking pids.max and pids.events](/journal/container-pids-limit-thread-errors/).
