LinuxCommandLibrary

systemctl-kill

Terminate running systemd services

TLDR

Send the SIGTERM signal to a unit to terminate it

$ systemctl kill [unit]
copy

Send a specific signal to a unit
$ systemctl kill [[-s|--signal]] [signal_number|signal_name] [unit]
copy

Send a SIGHUP signal to only the main process of a unit
$ systemctl kill [[-s|--signal]] SIGHUP --kill-whom main [unit]
copy

List all available signals
$ systemctl kill [[-s|--signal]] help
copy

SYNOPSIS

systemctl kill [OPTIONS...] UNIT...

PARAMETERS

-s, --signal=SIGNAL
    Specifies the signal to send to the processes. Common signals include SIGTERM (default for graceful shutdown), SIGKILL (forceful termination), or SIGHUP (often for reloads).

-p, --kill-who=WHO
    Determines which processes of the unit should receive the signal. Possible values include main (the main process of the unit), control (the control process), or all (all processes in the unit's control group, which is the default).

--kill-others
    If specified, also kill processes belonging to other units but associated with the unit's control group. Rarely needed for typical service management.

DESCRIPTION

The systemctl kill command is a powerful utility within the systemd ecosystem designed to send specific signals to processes belonging to one or more systemd units. Unlike directly using the kill command with process IDs, systemctl kill operates at the service level, targeting the control group associated with a unit. This ensures that all relevant processes of a service, or specific subsets of them, receive the intended signal.

By default, it sends a SIGTERM signal, which requests a graceful shutdown, but it can be configured to send any valid signal, such as SIGKILL for an immediate, non-graceful termination. This makes it invaluable for situations where a service is unresponsive and needs to be forcefully stopped, or when specific signals are required for reloads or other operational tasks. It provides a structured and consistent way to manage process termination for systemd-managed services, leveraging cgroups for precise targeting.

CAVEATS

Using SIGKILL should be a last resort as it prevents the service from performing cleanup operations, potentially leading to data corruption or inconsistent states. Always try SIGTERM first and wait for a short period before resorting to SIGKILL.

The command targets processes within systemd's control groups; processes not managed by systemd or outside the unit's cgroup will not be affected.

DIFFERENCE FROM SYSTEMCTL STOP

While systemctl stop attempts a graceful shutdown by executing the service's defined stop command, which might internally send SIGTERM, systemctl kill directly sends the specified signal to the target processes. This bypasses any service-specific stop logic and is used for more direct or forceful termination, especially when a service is unresponsive to conventional stop commands.

HISTORY

The kill subcommand is an integral part of systemctl, which itself was introduced with systemd as the primary service manager for Linux systems. systemd replaced older init systems like SysVinit and Upstart, bringing cgroup-based process management and declarative unit files. The kill subcommand specifically leverages these capabilities to provide a robust and controlled way to send signals to service processes, aligning with systemd's philosophy of centralized and efficient system management.

SEE ALSO

systemctl(1), kill(1), systemd.service(5), signal(7)

Copied to clipboard