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 workerCommon 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.
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 CMDkillall 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"Exercise: Bash Process Management
What does the "ps" command show by default?