kill Command Cheat Sheet
The kill command is a built-in shell utility (and a standalone binary /bin/kill) used to send signals to running processes. Despite its name, it can send any signal, not just termination signals.
Synopsis
kill [OPTIONS] [PID...]
kill -l [SIGNAL]
Basic Termination
Terminate a Process (Graceful)
Sends SIGTERM (15) by default. This asks the process to stop nicely (save data, close files, etc.).
kill 1234
Force Kill (Immediate)
Sends SIGKILL (9). The kernel removes the process immediately. The process cannot catch or ignore this signal. Data loss may occur.
kill -9 1234
Signals
List All Available Signals
kill -l
Common Signals
| ID | Name | Effect | Use Case |
|---|---|---|---|
| 1 | SIGHUP | Hangup | Reload configuration (e.g., kill -1 <pid> for nginx/apache) |
| 2 | SIGINT | Interrupt | Equivalent to Ctrl+C |
| 3 | SIGQUIT | Quit | Quit and dump core (Ctrl+\) |
| 9 | SIGKILL | Kill | Force kill (Cannot be caught) |
| 15 | SIGTERM | Terminate | Polite kill (Default) |
| 18 | SIGCONT | Continue | Resume a stopped process |
| 19 | SIGSTOP | Stop | Pause process (Cannot be caught) |
Sending Signals by Name or Number
All equivalent:
kill -1 1234
kill -HUP 1234
kill -SIGHUP 1234
Advanced Usage
Kill Multiple Processes
kill 1234 1235 1236
Kill All Processes You Can
⚠️ Dangerous: kill -9 -1 kills all processes you are allowed to kill (except the killing process itself). If run as root, this can crash the system.
Checking if a Process Exists
Sending signal 0 checks permissions and existence but doesn't affect the process.
if kill -0 1234; then
echo "Process 1234 is running."
else
echo "Process 1234 is NOT running."
fi
Process Groups
You can kill an entire process group by specifying a negative PID.
# Kill process group 1234
kill -TERM -1234
Exit Status
| Code | Meaning |
|---|---|
| 0 | Success |
| 1 | Failure (Permissions, No process found) |
Notes
- Bash Builtin:
type killusually returnskill is a shell builtin. This allows you to kill jobs using%1syntax. - Alternatives:
pkill: Kill by name pattern.killall: Kill by exact name.xkill: Kill graphical window by clicking on it.