In this lesson, you will learn how to distinguish between a polite request to stop a process and a forceful, immediate termination by the kernel.
The Polite Request: SIGTERM (Signal 15)
When you run the command kill <PID>, Linux sends a SIGTERM signal to that process. Think of this as a polite request to "please shut down."
Because it is a signal, the application has the ability to "catch" it. Well-behaved programs use this time to perform a graceful shutdown: they finish writing data to disk, close network connections, release temporary files, and inform other processes that they are leaving. This prevents data corruption and ensures that system state remains consistent.
The Forceful End: SIGKILL (Signal 9)
Sometimes, a process is "stuck"—perhaps it is trapped in an infinite loop or refusing to respond to the SIGTERM request. In these cases, you use kill -9 <PID>, which sends SIGKILL.
Unlike SIGTERM, SIGKILL cannot be caught, ignored, or handled by the process. The process is not even given a chance to run any cleanup code. Instead, the Linux kernel immediately removes the process from the CPU scheduler and reclaims its memory and resources. Because the process is never notified that it is being terminated, it cannot perform any cleanup.
A Quick Comparison
| Feature | SIGTERM (15) | SIGKILL (9) |
|---|---|---|
| Intent | Request to stop gracefully | Immediate termination |
| Handling | Can be caught or ignored | Cannot be caught or ignored |
| Data Safety | High (cleanup occurs) | Low (potential for data loss) |
| Usage | Always try this first | Only use as a last resort |
Example workflow:
- Try
kill 1234(sendsSIGTERM). - Wait a few seconds for the process to exit.
- If the process is still running, escalate to
kill -9 1234(sendsSIGKILL).
Key Takeaway: Use SIGTERM as your primary tool to allow applications to save state and clean up, reserving SIGKILL as an emergency measure for unresponsive processes when all other options fail.