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
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 jobsOptions
| Signal | What it does |
|---|---|
| -TERM / -15 | Default: ask process to terminate |
| -KILL / -9 | Force kill (uncatchable) |
| -INT / -2 | Interrupt (like Ctrl-C) |
| -HUP / -1 | Hangup (often = reload config) |
| -0 | No signal; just check the PID exists |
| -l | List 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.