kill
Terminate processes
TLDR
Terminate a program using the default SIGTERM (terminate) signal
List available signal names (to be used without the SIG prefix)
Terminate a program using the SIGHUP (hang up) signal. Many daemons will reload instead of terminating
Terminate a program using the SIGINT (interrupt) signal. This is typically initiated by the user pressing
Signal the operating system to immediately terminate a program (which gets no chance to capture the signal)
Signal the operating system to pause a program until a SIGCONT ("continue") signal is received
Send a SIGUSR1 signal to all processes with the given GID (group id)
SYNOPSIS
kill [options] <pid> ...
kill -s <signal> <pid> ...
kill -<signal> <pid> ...
kill -l [signal]
PARAMETERS
-s <signal>, --signal <signal>
Specifies the signal to send. Can be a signal name (e.g., TERM, KILL, HUP) or a signal number (e.g., 15, 9, 1).
-l, --list
Lists all signal names supported by the system. If a signal number is provided, it will list the corresponding signal name.
-L, --table
Lists signal names and their corresponding numbers in a table format, often including default actions.
-<signal>
A shorthand for sending a specific signal by its name or number (e.g., -9 for SIGKILL, -TERM for SIGTERM).
--pid
This is the default mode; arguments are interpreted as Process IDs (PIDs).
--pgid
Operates on Process Group IDs instead of PIDs. Sends the signal to all processes within the specified process group.
--user <user>
Operates on processes owned by the specified user. This is a non-standard extension found in some `kill` implementations (e.g., `procps-ng`).
--comm <command>
Operates on processes whose command name matches the argument. This is a non-standard extension, typically found in `pkill` but sometimes in `kill` implementations.
--verbose
Provides more verbose output, detailing the signal sent and target processes. This is a non-standard extension.
DESCRIPTION
The `kill` command is a fundamental Unix/Linux utility used to send signals to processes. A signal is a software interrupt sent to a process, indicating an event has occurred. By default, `kill` sends the SIGTERM (Terminate) signal (signal number 15), which politely asks a process to shut down, allowing it to perform cleanup tasks like saving data and closing files. If a process does not respond to SIGTERM or is misbehaving, the SIGKILL (Kill) signal (signal number 9) can be used. SIGKILL is an unblockable, uncatchable signal that forces the immediate termination of a process, without allowing it to perform any cleanup. Processes are typically identified by their Process ID (PID). The `kill` command is often implemented as a shell built-in for efficiency and is essential for system administration, managing misbehaving applications, or freeing up resources.
CAVEATS
Permissions: You can only send signals to processes that you own, or if you are the root user.
SIGKILL (9): This signal cannot be caught, ignored, or blocked by the target process, ensuring immediate and forceful termination. Use it as a last resort, as it prevents the process from performing any cleanup.
SIGTERM (15): This is the preferred signal for graceful shutdown, allowing the process to clean up resources before exiting.
Shell Built-in vs. /bin/kill: The `kill` command is often a shell built-in (e.g., in Bash, Zsh) which may have slightly different options or behaviors than the standalone `/bin/kill` utility. The shell built-in usually takes precedence for efficiency.
COMMON SIGNALS
Beyond SIGTERM and SIGKILL, several other signals are commonly used:
SIGTERM (15): The default, polite request to terminate. The process can catch this and perform cleanup.
SIGKILL (9): Forceful termination. The process cannot ignore or block this signal.
SIGHUP (1): 'Hang up'. Often used to instruct daemon processes to re-read their configuration files without restarting.
SIGINT (2): Interrupt from keyboard, typically sent by Ctrl+C.
SIGSTOP (19 or 23): Stops a process without killing it. The process is paused.
SIGCONT (18 or 25): Resumes a stopped process.
GRACEFUL VS. FORCEFUL TERMINATION
Understanding the difference is crucial:
Graceful Termination (e.g., with SIGTERM): This allows the process to catch the signal, close open files, save unsaved data, release locks, and exit cleanly. It's the preferred method to prevent data loss or corruption.
Forceful Termination (e.g., with SIGKILL): This abruptly stops the process without any opportunity for cleanup. While effective for unresponsive processes, it can leave behind temporary files, corrupted data, or orphaned resources, as the process cannot perform its normal shutdown routines.
HISTORY
The `kill` command has been a part of Unix since its earliest versions, making it one of the most fundamental tools for process management. Its initial purpose was simple: to send a specified signal to a process identified by its PID. Given its crucial role in system control, especially for stopping misbehaving processes or gracefully shutting down services, `kill` was quickly implemented as a shell built-in in various Unix shells (like `sh`, `csh`, and later `bash`). This ensures that the command is always available and can be executed quickly without needing to fork a new process, even in low-resource or critical system states. While the core functionality has remained consistent, later utilities like `pkill` and `killall` were developed to extend signal sending capabilities, allowing users to target processes based on names, users, or other attributes, thereby simplifying common process management tasks.