The kill command in Linux

kill sends a signal to a process — despite the name, not always a lethal one. The default signal, SIGTERM (15), politely asks the program to shut down, letting it save state and clean up. SIGKILL (9) is the last resort: the kernel terminates the process instantly, no questions asked, no cleanup. Always try plain kill before kill -9.

How kill works

Signals are the kernel's asynchronous tap on a process's shoulder, and kill is the syscall (and command) that sends them. Each signal has a default action — terminate for SIGTERM, ignore for SIGCHLD, stop for SIGSTOP — and a process may install handlers to override defaults: catch SIGTERM to flush buffers and exit cleanly, catch SIGHUP to reload configuration. A signal is a number and a convention; the graceful behavior lives in the receiving program.

Two signals cannot be caught, blocked or ignored: SIGKILL and SIGSTOP. That is a deliberate guarantee — the administrator always holds a lever the process cannot wire shut. It also defines SIGKILL's cost: the process gets no final instruction, so nothing is flushed, no temp files removed, no locks released. Permission-wise, you may signal only your own processes (matching UID); root signals anything. The rare SIGKILL survivor is a process in uninterruptible I/O sleep (state D) — it is not resisting; it simply cannot hear anything until the kernel-level I/O returns.

Syntax

kill [-SIGNAL] PID...

Common options

OptionWhat it does
(default)SIGTERM (15): request a graceful shutdown.
-9SIGKILL: force termination immediately. Cannot be caught or ignored.
-HUPSIGHUP (1): many daemons reload their configuration on this signal.
-STOP / -CONTPause a process and resume it later.
-lList all signal names.

How to use kill: examples

$ kill 4321

Ask process 4321 to terminate gracefully.

$ kill -9 4321

Force it. Use only when the polite version was ignored.

$ killall node

Signal every process by name instead of PID.

$ pkill -f "python server.py"

Signal processes whose full command line matches a pattern.

$ kill -HUP $(pgrep nginx | head -1)

Tell a daemon to reload configuration without downtime.

Real-world use cases for kill

Freeing a port a dead app still holds

"Address already in use" on port 3000: kill $(lsof -t -i:3000) terminates whatever holds it. The lsof -t flag prints bare PIDs precisely so they can be fed to kill like this.

Graceful restarts without dropped requests

Sending SIGHUP instead of killing: kill -HUP $(cat /var/run/nginx.pid) makes nginx re-read config and gracefully cycle workers — the mechanism behind every zero-downtime reload.

Pro tips and common mistakes

Frequently asked questions about kill

What is the difference between kill and kill -9?

Plain kill sends SIGTERM, which the program can handle: close files, flush data, exit cleanly. kill -9 sends SIGKILL, which the program never sees — the kernel just removes it. -9 risks corrupted files and orphaned locks, so it is the fallback, not the default.

How do I find the PID to kill?

ps aux | grep programname, or directly pgrep programname. pkill and killall skip the PID step entirely by matching on the name.

Why does a process survive kill -9?

Almost nothing survives SIGKILL. The exceptions are processes in uninterruptible I/O sleep (state D, usually stuck on disk/NFS) and zombies, which are already dead and only need their parent to acknowledge them.

Related commands

grep

Find lines matching a pattern in files or piped input — the workhorse of text search.

ps

See what is running, find a process ID, and combine with grep to hunt down a program.

Want to build real fluency? The interactive course takes you through kill and every other essential command with guided, checked exercises.