kill, pkill & killall Cheatsheet
These commands are used to send signals to processes, typically to terminate them. The primary difference between them lies in how they identify the target process(es).
Understanding Signals
A signal is a way for the operating system to interrupt a process and tell it to perform an action. You can specify a signal by name (e.g., `TERM`) or number (e.g., `15`).
| Signal | Number | Description |
|---|---|---|
TERM | 15 | **Graceful shutdown.** Asks the process to terminate gracefully, giving it time to clean up resources. This is the default signal for the kill command. |
KILL | 9 | **Forceful shutdown.** Terminates the process immediately and unconditionally. It cannot be caught, blocked, or ignored by the process. Use this as a last resort. |
HUP | 1 | **Hang up.** Often used to tell a process (like a daemon) to reload its configuration without shutting down. |
Command Reference
| Command | Description | Example |
|---|---|---|
kill | Sends a signal to a process identified by its **PID** (Process ID). It is the most precise way to terminate a single process. | kill 12345kill -9 12345 |
pkill | Sends a signal to processes based on a **partial or full name**. It is a convenient way to kill processes without knowing their PIDs. | pkill firefoxpkill -TERM sshd |
killall | Sends a signal to all processes with an **exact name**. Use with caution as it can terminate multiple processes with the same name. | killall nginxkillall -HUP httpd |