What are signals in Linux and what do SIGTERM, SIGKILL, and SIGHUP do?
Learn what Linux signals are and how SIGTERM, SIGKILL, and SIGHUP work — graceful shutdown, force kill, and config reloads — with kill command examples.
Expected Interview Answer
Signals are asynchronous notifications the kernel or a process sends to another process to tell it something happened or ask it to act; SIGTERM politely requests termination, SIGKILL forcibly kills it immediately, and SIGHUP originally signaled a terminal hangup and is now often used to tell daemons to reload their configuration.
Each signal has a number and a default action, and processes can install handlers to catch most signals and respond gracefully. SIGTERM (15) is the default kill signal and can be caught to allow cleanup, SIGKILL (9) cannot be caught, blocked, or ignored so it always terminates the process, and SIGHUP (1) is sent when a controlling terminal closes but is conventionally repurposed to trigger config reloads. You send signals with kill, killall, or pkill, e.g. 'kill -TERM pid' or 'kill -9 pid'.
- Enables graceful shutdown via catchable SIGTERM
- SIGKILL guarantees a stuck process can be stopped
- SIGHUP lets daemons reload config without restarting
- Signals allow inter-process communication and control
- Handlers let programs clean up resources before exiting
AI Mentor Explanation
Signals are the umpire's gestures to the players. SIGTERM is raising the finger and asking the batter to walk off — they can gather their gear first. SIGKILL is security physically removing someone instantly, no chance to pack up. SIGHUP is the umpire calling drinks, prompting the team to regroup and rethink their setup without leaving the ground.
Step-by-Step Explanation
Step 1
Understand what a signal is
A numbered, asynchronous notification delivered to a process, each with a default action.
Step 2
Send SIGTERM first
Use 'kill pid' (default TERM) to request a graceful shutdown the process can handle.
Step 3
Escalate to SIGKILL if stuck
Use 'kill -9 pid' only when a process ignores TERM; it cannot be caught or ignored.
Step 4
Use SIGHUP to reload
Send 'kill -HUP pid' to a daemon like nginx to re-read its configuration without restarting.
Step 5
Handle signals in code
Install handlers (e.g. trap in bash, signal() in C) to clean up resources before exiting.
What Interviewer Expects
- That SIGKILL cannot be caught, blocked, or ignored
- That SIGTERM is catchable and allows graceful cleanup
- The conventional SIGHUP reload use for daemons
- Signal numbers 15, 9, and 1 respectively
- How to send signals with kill, pkill, or killall
Common Mistakes
- Reaching for kill -9 first instead of SIGTERM
- Thinking SIGKILL can be caught by a handler
- Confusing SIGHUP's hangup origin with its reload convention
- Assuming all signals can be ignored
- Not knowing kill without a number sends SIGTERM, not SIGKILL
Best Answer (HR Friendly)
“Signals are little messages the system uses to tell programs what to do. SIGTERM politely asks a program to close and tidy up, SIGKILL forces it to stop right away with no chance to save, and SIGHUP is commonly used to tell background services to reload their settings without fully restarting.”
Code Example
# find the process id
pgrep nginx
# graceful termination (SIGTERM, signal 15) — the default
kill 1234
kill -TERM 1234
# force kill a stuck process (SIGKILL, signal 9)
kill -9 1234
# tell a daemon to reload its config (SIGHUP, signal 1)
kill -HUP 1234
# trap SIGTERM in a bash script for cleanup
trap 'echo cleaning up; exit' TERMFollow-up Questions
- Why can't SIGKILL be caught or ignored?
- What is the difference between kill and killall?
- How do you handle SIGTERM for graceful shutdown in a program?
- What is a zombie process and can signals remove it?
- How does SIGSTOP differ from SIGTSTP (Ctrl+Z)?
MCQ Practice
1. Which signal cannot be caught, blocked, or ignored?
SIGKILL (9) is always handled by the kernel and cannot be intercepted, so it reliably terminates a process.
2. What signal does 'kill pid' send by default?
With no signal specified, kill sends SIGTERM (15), a catchable request to terminate gracefully.
3. SIGHUP is conventionally used by daemons to do what?
Though it originally meant terminal hangup, many daemons repurpose SIGHUP to re-read their config without restarting.
Flash Cards
What is SIGTERM? — Signal 15 — a catchable, polite request to terminate, allowing cleanup.
What is SIGKILL? — Signal 9 — an uncatchable signal that forcibly terminates a process instantly.
What is SIGHUP? — Signal 1 — originally a terminal hangup, now often used to reload daemon config.
What does 'kill pid' send? — SIGTERM by default, not SIGKILL.
Continue Learning
Related Interview Questions
What is the difference between kill, kill -9, and killall in Linux?
easy
What is the difference between a foreground and a background process in Linux?
easy
What is the difference between grep, sed, and awk in Linux?
medium
Why does Ctrl+C stop a whole pipeline, and why do background jobs die when you close the terminal?
medium