Skip to content
Latchkey

kill: Usage, Options & Common CI Errors

kill sends a signal (by default SIGTERM) to a process by PID.

kill is the cleanup tool for background services in CI. The key distinction is graceful SIGTERM (let it shut down) versus forceful SIGKILL/-9 (cannot be caught), and when each is appropriate.

What it does

kill sends a signal to one or more processes by PID. The default is SIGTERM (15), a polite "please exit" the process can trap to clean up. SIGKILL (9) cannot be caught and forcibly terminates it.

Common usage

Terminal
kill $PID                      # SIGTERM (graceful)
kill -9 $PID                   # SIGKILL (forceful, last resort)
kill -TERM $PID                # named signal
kill -0 $PID                   # test if PID exists (sends nothing)
pkill -f 'node server.js'      # by command pattern
kill $(jobs -p)                # all background jobs

Options

SignalWhat it does
-TERM / -15Default: ask process to terminate
-KILL / -9Force kill (uncatchable)
-INT / -2Interrupt (like Ctrl-C)
-HUP / -1Hangup (often = reload config)
-0No signal; just check the PID exists
-lList signal names/numbers

Common errors in CI

kill: (PID) - No such process means it already exited (often harmless during cleanup; guard with kill -0 first). "Operation not permitted" means another user owns the process (use sudo or match UIDs). Reaching for -9 immediately skips graceful shutdown and can corrupt state or leave temp files - try SIGTERM, wait, then SIGKILL. In containers, PID 1 ignores SIGTERM unless it explicitly handles it.

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →