A signal is a short message the kernel delivers to a process. The four common ones:
SIGTERM (15) is a polite request to stop. kill <pid> sends it by default. A process can catch it. Then it can finish the work it's doing, close connections and exit cleanly.
SIGKILL (9) can't be caught, blocked or ignored. The kernel ends the process at once, so no cleanup code runs:
- Buffers aren't flushed (written out).
- Temporary files are left behind.
- Locks are left behind.
Use it only after SIGTERM didn't work.
SIGINT (2) is what the terminal sends when you press Ctrl-C. By default it also ends the process. Programs usually handle it the same way as SIGTERM.
SIGHUP (1) first meant "the terminal hung up". By default it also ends the process. Many daemons (background services), such as nginx, treat it as "reload your configuration".
The usual way to stop a service: send SIGTERM, wait a grace period, then send SIGKILL.
- SIGTERM is the default signal of kill, and a process can catch it to shut down cleanly.
- SIGKILL can't be caught or ignored, so no cleanup runs.
- SIGINT is what the terminal sends when you press Ctrl-C.
- SIGHUP means the terminal hung up, and daemons often use it to reload config.
- To stop a service, send SIGTERM, wait, then send SIGKILL.