Bash Terminate Process

kill sends signals to processes, and choosing the right signal number is the difference between a graceful shutdown and a forced termination.

Sending Signals with kill

Despite the name, kill does not inherently destroy a process — it sends it a signal, and what happens next depends on that process's own signal handling. Run without any flag, kill sends signal 15 (SIGTERM), a polite request that well-behaved programs can catch and use to shut down cleanly, saving state or closing connections first.

Basic kill

$ ps aux | grep worker
alice     4521  0.4  0.3  98200 21400 pts/1    S    09:40   0:05 python3 worker.py
$ kill 4521
$ ps aux | grep worker
alice     4602  0.0  0.0   9032   980 pts/1    S+   09:44   0:00 grep worker

Common Signal Numbers

Linux defines dozens of signals, but a handful come up constantly in day-to-day shell work. Each has both a name and a number, and both forms are accepted by kill interchangeably.

SignalNumberDescription
SIGHUP1originally 'terminal hangup'; many daemons treat it as 'reload your config'
SIGINT2interrupt; what your terminal sends when you press Ctrl+C
SIGTERM15the default and polite request to terminate; catchable and ignorable
SIGKILL9immediate, uncatchable termination handled directly by the kernel

kill -9: The Last Resort

kill -9 sends SIGKILL, which the kernel enforces directly without ever notifying the target process, so it cannot be caught, blocked, or ignored. That makes it effective against a genuinely frozen process, but it also skips any cleanup code the program would normally run, which can leave temporary files, lock files, or half-written database records behind.

Force Killing

$ kill -9 4521
$ ps -p 4521
PID TTY      TIME CMD

killall and pkill by Name

Looking up a PID first isn't always necessary. killall sends a signal to every process matching an exact program name, and pkill matches against a pattern, both accepting the same signal flags as kill.

Killing by Name

$ killall -15 node
$ pkill -9 -f "worker.py --queue=default"
Note: Reach for kill -9 only after a plain kill (SIGTERM) has failed to stop the process after a few seconds. Skipping straight to -9 habitually means processes never get the chance to shut down cleanly, which can corrupt data files or leave orphaned locks.
Note: Run kill -l to print every signal name and number the system supports, in case you need one beyond the common four covered here.

Exercise: Bash Process Management

What does the "ps" command show by default?