Stopping Processes: kill

kill sends a signal to a process, most often to make it stop.

Syntaxkill [-SIGNAL] PID

kill does not only "kill" — it sends a signal to a process by its PID. Different signals ask for different behaviour.

Signals being sent to a running processProcessPID 981SIGTERM (15)please stopSIGKILL (9)force stop
SIGTERM asks politely; SIGKILL cannot be ignored.

Common signals

  • SIGTERM (15) — the default. Asks the process to shut down cleanly.
  • SIGKILL (9) — forces it to stop immediately; it cannot be caught or ignored.
  • SIGHUP (1) — often tells a service to reload its config.

killall name and pkill name stop processes by name instead of PID.

Example

Example · bash
# Ask a process to stop cleanly
kill 981

# Force a stuck process to die
kill -9 981

# Stop every process matching a name
pkill firefox

# Reload a service's config without a full restart
kill -HUP 981

When to use it

  • A developer sends 'kill -15 $(pgrep myapp)' for a graceful shutdown of an application before redeploying.
  • A sysadmin uses 'kill -9' as a last resort to forcibly terminate a hung process that ignores SIGTERM.
  • A CI job uses 'pkill -f pytest' to terminate all pytest processes after a timeout, cleaning up before re-running tests.

More examples

Send SIGTERM for graceful stop

Sends the default SIGTERM (signal 15) which asks a process to clean up and exit gracefully.

Example · bash
# Find the PID first
pgrep -l myapp
# 5432 myapp

# Send SIGTERM (default, polite shutdown)
kill 5432

# Verify it stopped
pgrep myapp || echo 'Process stopped'

Force kill an unresponsive process

Uses -9 (SIGKILL) to forcibly terminate a process; unlike SIGTERM, the kernel kills it immediately.

Example · bash
# SIGKILL cannot be caught or ignored
kill -9 5432

# Or using signal name
kill -SIGKILL 5432

# Kill all processes named 'zombie'
pkill -9 zombie

Kill processes by name or pattern

Uses pkill to target processes by name or full command line, and sends SIGHUP to trigger a config reload.

Example · bash
# Kill all processes named exactly 'python3'
pkill python3

# Kill by matching full command line
pkill -f 'python3 worker.py'

# Send SIGHUP to reload nginx config
pkill -HUP nginx

Discussion

  • Be the first to comment on this lesson.