Great question! When you want to kill a Linux process, the choice of signal matters a lot, especially if you want to be "rude" and not give the process any chance to clean up or handle the signal gracefully.
Let's break down the signals you mentioned: SIGTERM (15), SIGKILL (9), and SIGILL (4), and compare them in detail.
1. SIGTERM (Signal 15) — Termination Request
- Purpose: This is the default signal sent by the
kill command if no signal is specified.
- Behavior: It politely asks the process to terminate.
- Process reaction: The process can catch this signal and run cleanup code, close files, save state, or even ignore it.
- Use case: Graceful shutdown, giving the process a chance to exit cleanly.
- Example:
kill -15 <pid> or just kill <pid>
Summary:
SIGTERM is not rude. It’s a polite request to terminate.
2. SIGKILL (Signal 9) — Kill Immediately
- Purpose: This signal cannot be caught, blocked, or ignored by the process.
- Behavior: The kernel immediately stops the process and frees its resources.
- Process reaction: The process does not get any chance to run signal handlers or cleanup code.
- Use case: When you want to forcibly and immediately kill a process, no questions asked.
- Example:
kill -9 <pid>
Summary:
SIGKILL is the rudest way to kill a process. It’s immediate and uncatchable.
3. SIGILL (Signal 4) — Illegal Instruction
- Purpose: Sent when a process attempts to execute an illegal, malformed, or privileged instruction.
- Behavior: The process can catch this signal, but it usually indicates a serious error or bug.
- Process reaction: If caught, the process can handle it; otherwise, it terminates and may produce a core dump.
- Use case: Typically used by the system to indicate a program error, not for killing processes.
- Example:
kill -4 <pid>
Summary:
SIGILL is not intended for killing processes. It’s a fault signal, not a termination signal.
Comparison and Recommendation
| Signal | Can be caught/ignored? | Gives process cleanup time? | Typical use case | Rudeness level |
|---|
| SIGTERM (15) | Yes | Yes | Graceful termination | Polite |
| SIGKILL (9) | No | No | Immediate, forced termination | Extremely rude (best for your need) |
| SIGILL (4) | Yes | Yes | Illegal instruction fault | Not for killing processes |
Conclusion
- If you want to kill a process in an extremely rude way that does not give it any time to run signal handlers, SIGKILL (9) is the best and standard choice.
- SIGTERM (15) is polite and allows cleanup.
- SIGILL (4) is not designed for killing processes and can be caught or ignored.
Additional notes:
- Even SIGKILL does not guarantee immediate termination if the process is stuck in uninterruptible kernel I/O (e.g., waiting on disk or network).
- You cannot "kill" kernel threads or processes in certain states with SIGKILL.
- Using SIGKILL should be a last resort after trying SIGTERM.
Summary:
Use kill -9 <pid> for the rudest, no-cleanup, immediate kill.