kill — how you stop or control processes by sending signals.
What kill really does
kill doesn’t just “kill”; it sends
a signal to one or more processes.
· Default signal = SIGTERM (15) → “please exit cleanly.”
· Only SIGKILL (9) and SIGSTOP (19) can’t be caught/ignored.
·
You can signal by
PID, job id (like %1), or
even process group.
You can only signal processes you own. root can signal any.
Quick syntax
kill PID # send SIGTERM (polite stop)kill -SIGTERM PID # same as abovekill -15 PID # same as above (15 = SIGTERM)kill -9 PID # SIGKILL (force stop, last resort)kill -SIGINT PID # like pressing Ctrl+C to that processkill -SIGSTOP PID # pause (cannot be caught)kill -SIGCONT PID # continue a stopped processkill -HUP PID # “hang up” (many daemons = reload config)kill -l # list signals on your systemMultiple targets:
kill -TERM 1234 5678 9012By job id (current shell):
sleep 300 & # background job -> [1] PIDkill %1 # signal job #1Signal a whole process group (advanced but useful):
kill -TERM -1234 # minus PID means “process group 1234”Common signals (you’ll actually use)
|
Name |
Num |
Meaning / Use |
|
SIGTERM |
15 |
Ask to exit cleanly (default). Prefer this first. |
|
SIGINT |
2 |
Interrupt (like Ctrl+C to foreground job). |
|
SIGHUP |
1 |
“Hang up”; many services interpret as reload config. |
|
SIGKILL |
9 |
Force kill immediately (can’t be trapped). Last resort. |
|
SIGSTOP |
19 |
Pause a process (can’t be trapped). |
|
SIGCONT |
18 |
Resume a stopped process. |
|
SIGTSTP |
20 |
Stop from terminal (Ctrl+Z). |
Numbers can differ slightly across UNIXes; names are portable.
Finding what to kill
ps -ef | grep myapppgrep -fl myapp # nicer: list PIDs and full namestop / htop # interactively find PIDs (top: press k to kill)kill vs pkill vs killall
·
kill
PID: by ID (precise).
·
pkill
pattern: by name/regex (be
careful; affects matching processes).
·pkill -f "python.*train.py" # match full cmdline (-f)
·pkill -u alice chrome # only user alice’s chrome
·
killall
name: by exact command
name (Linux).
On macOS, killall targets apps by name (different
behavior). On Linux it’s safe for CLI names.
Typical student scenarios
1) Nicely stop a runaway job
pgrep -fl myscript # get PID(s)kill -TERM <PID>2) If it ignores TERM
kill -INT <PID> # try interrupt (like Ctrl+C)kill -HUP <PID> # some daemons reload / exit cleanlykill -KILL <PID> # LAST resort (may lose data)3) Pause & resume a heavy process
kill -STOP <PID> # pause# … free the CPU/GPU/disk …kill -CONT <PID> # resume4) Reload a service without full restart (if it supports SIGHUP)
sudo kill -HUP $(cat /run/nginx.pid) # nginx common patternReading errors (and fixes)
·
kill:
(PID) - No such process → it
already exited or wrong PID.
·
Operation
not permitted → you don’t own
it; use sudo (if appropriate).
· Nothing happens → process may be ignoring the signal; escalate gently (TERM → INT/HUP → KILL).
Safety tips
·
Prefer SIGTERM first; SIGKILL
only if necessary (it skips cleanup, can leave temp files/locks).
·
Double-check the PID
(ps -p PID -o pid,cmd) before signaling.
·
When matching by
name, narrow the pattern (pkill -u yourname exactname).
· On shared systems, don’t kill processes you don’t own unless you’re the admin.
Mini-lab (10–15 min)
# Start a test jobsleep 300 & # note job id and PID: echo $! # 1) Interrupt like Ctrl+Ckill -INT $! # job should exit # Start againsleep 300 & # 2) Stop and continuekill -STOP $!sleep 1 && ps -p $! -o pid,stat,cmd # STAT should show T (stopped)kill -CONT $! # 3) Terminate politely, then force (if still running)kill -TERM $!sleep 1 && ps -p $! || echo "Ended"# (If still there: kill -KILL $!)Exam-ready bullets
·
kill sends signals (default SIGTERM
15) to PIDs/jobs/groups.
·
Use names or
numbers: kill -TERM pid, kill
-15 pid.
· SIGKILL (9) & SIGSTOP (19) cannot be caught/ignored.
·
Find targets with
ps, pgrep, top/htop.
·
pkill/killall kill by name (broader; be cautious).
·
Process groups: kill -TERM -PGID to signal a whole group.
· Admin rule: TERM → (INT/HUP) → KILL in that order.
Want this plus ps/top on a printable monitoring sheet for your class? I can
format it neatly.