What is the difference between kill, kill -9, and killall in Linux?
Learn the difference between kill, kill -9, and killall in Linux — SIGTERM vs SIGKILL, signalling by PID vs name, and when to force-terminate safely.
Expected Interview Answer
kill sends a signal to a process by PID (SIGTERM by default, asking it to shut down gracefully); kill -9 sends SIGKILL, which forcibly terminates the process immediately without cleanup; killall targets processes by name rather than PID, signalling every matching process at once.
kill is not really about killing — it delivers any signal, and its default SIGTERM (15) lets a program flush buffers, close files, and exit cleanly. SIGKILL (9) cannot be caught, blocked, or ignored, so the kernel destroys the process instantly, risking data loss and orphaned resources. killall is a convenience wrapper that resolves a name to all its PIDs and signals them together, which is powerful but dangerous because it can hit unintended matches.
- kill (SIGTERM) allows graceful, clean shutdown
- kill -9 (SIGKILL) guarantees termination of unresponsive processes
- killall stops many same-named processes in one command
- Signals let you pause, resume, or reload without restarting
- Precise PID targeting avoids collateral damage
AI Mentor Explanation
kill is the umpire raising a finger and calmly asking a batter to walk off — SIGTERM gives them time to collect their bat and gloves. kill -9 is a runner-out dismissal that ends the innings instantly, no protest allowed. killall is like calling all openers named 'Smith' back to the pavilion at once, so you might dismiss more players than you intended.
Step-by-Step Explanation
Step 1
Find the PID
Use ps, pgrep, or top to locate the process identifier you want to signal.
Step 2
Try a graceful stop
Run kill <PID> to send the default SIGTERM and let the process shut down cleanly.
Step 3
Wait and verify
Give it a few seconds, then check with ps whether the process has actually exited.
Step 4
Force if unresponsive
If it ignores SIGTERM, escalate with kill -9 <PID> to send an uncatchable SIGKILL.
Step 5
Signal by name when needed
Use killall <name> to signal all processes with that command name, verifying the name first with pgrep.
What Interviewer Expects
- Knowing kill sends signals, not just terminates
- SIGTERM (15) vs SIGKILL (9) difference
- Why SIGKILL cannot be caught or ignored
- killall targets by name, pkill by pattern
- Awareness that -9 risks data loss and should be a last resort
Common Mistakes
- Thinking kill only kills and cannot send other signals
- Reaching for kill -9 first instead of trying SIGTERM
- Confusing killall with pkill semantics
- Not realising killall can hit unintended same-named processes
- Believing SIGKILL lets the process clean up its resources
Best Answer (HR Friendly)
“kill politely asks a program to close so it can save its work first, while kill -9 forces it to stop instantly with no chance to tidy up. killall does the same thing but targets programs by their name, so it can stop several at once.”
Code Example
# Find the process
pgrep -l nginx
# Ask it to shut down cleanly (SIGTERM = 15)
kill 4821
# Still running? Force it (SIGKILL = 9, uncatchable)
kill -9 4821
# Signal every process named 'nginx' at once
killall nginx
# List available signals
kill -lFollow-up Questions
- What is the difference between SIGTERM and SIGKILL?
- Why can a process ignore SIGTERM but not SIGKILL?
- How does pkill differ from killall?
- What happens to child processes when a parent is killed?
- How do you send SIGHUP to make a daemon reload its config?
MCQ Practice
1. Which signal does a plain 'kill <PID>' send by default?
With no signal specified, kill sends SIGTERM (15), which asks the process to terminate gracefully.
2. Why is SIGKILL (kill -9) considered forceful?
SIGKILL is handled by the kernel and cannot be trapped, so the process is destroyed immediately with no cleanup.
3. How does killall select its targets?
killall signals all processes matching a given command name, unlike kill which needs a numeric PID.
Flash Cards
Default signal of kill? — SIGTERM (15) — a graceful request to terminate.
What does kill -9 send? — SIGKILL (9) — an uncatchable, immediate forced termination.
Can SIGKILL be ignored? — No. It cannot be caught, blocked, or handled by the process.
How does killall differ from kill? — killall targets processes by name; kill targets a specific PID.
Continue Learning
Related Interview Questions
What are signals in Linux and what do SIGTERM, SIGKILL, and SIGHUP do?
medium
What is the difference between a shell and a terminal in Linux?
easy
Why does Ctrl+C stop a whole pipeline, and why do background jobs die when you close the terminal?
medium
What do the Linux file permissions rwx mean and how does chmod work?
easy