kill — Send Signals to Processes
Terminate, stop or control processes with signals – kill targets by PID, killall and pkill by name. Covers SIGTERM, SIGKILL and safe usage.
kill is your central tool for sending signals to running processes – to terminate them gracefully, force-kill them, pause them or tell a daemon to reload its configuration. By default kill sends the polite SIGTERM (15), which lets a program clean up; kill -9 (SIGKILL) forces the end with no cleanup and risks data loss, so reach for it only as a last resort. killall and pkill match by name and can easily hit too many processes, so check first with pgrep.
kill — By Process ID
kill <pid> — Send SIGTERM (graceful termination) to a process by PID.
kill 1234kill -9 <pid> — Send SIGKILL (force kill, cannot be caught or ignored).
kill -9 1234kill -SIGTERM <pid> — Send SIGTERM by name (same as kill without flags).
kill -SIGTERM 1234kill -<signal> <pid> — Send a specific signal by number or name.
kill -HUP 1234kill <pid1> <pid2> <pid3> — Send SIGTERM to multiple processes.
kill 1234 1235 1236kill -0 <pid> — Check if a process exists (signal 0 sends nothing, just checks).
kill -0 1234 && echo 'Process exists' || echo 'Process gone'kill -l — List all available signal names and numbers.
kill -lkillall — By Process Name
killall <name> — Send SIGTERM to all processes matching the exact name.
killall nginxkillall -9 <name> — Force kill all processes matching the name.
killall -9 php-fpmkillall -i <name> — Interactive mode: ask for confirmation before killing each process.
killall -i python3killall -u <user> — Kill all processes owned by a specific user.
killall -u testuserkillall -u <user> <name> — Kill processes by name owned by a specific user.
killall -u www-data php-fpmkillall -o <time> <name> — Kill only processes older than the specified time.
killall -o 1h php-fpmkillall -y <time> <name> — Kill only processes younger than the specified time.
killall -y 5m my-scriptkillall -w <name> — Wait for all killed processes to die before returning.
killall -w nginxkillall -r '<regex>' — Kill processes matching a regular expression.
killall -r 'worker-[0-9]+'pkill — By Pattern
pkill <pattern> — Send SIGTERM to processes whose name matches the pattern.
pkill firefoxpkill -9 <pattern> — Force kill processes matching the pattern.
pkill -9 chromepkill -f '<pattern>' — Match against the full command line (not just the process name).
pkill -f 'python3 worker.py'pkill -u <user> — Kill all processes owned by a user.
pkill -u guestpkill -t <tty> — Kill all processes on a specific terminal.
pkill -t pts/3pkill -P <ppid> — Kill all child processes of a parent PID.
pkill -P 1234pkill -x <name> — Match the exact process name only (no partial matches).
pkill -x python3Finding Process IDs
pgrep <pattern> — Find PIDs of processes matching a pattern (companion to pkill).
pgrep nginxpgrep -l <pattern> — Show PIDs and process names.
pgrep -l phppgrep -a <pattern> — Show PIDs and full command lines.
pgrep -a pythonpgrep -f '<pattern>' — Match against the full command line.
pgrep -f 'node server.js'pidof <name> — Find the PID of a running program by exact name.
pidof nginxImportant Signals
SIGTERM (15) — Graceful termination. The process can catch it and clean up. Default signal.
kill -TERM 1234 # or just: kill 1234SIGKILL (9) — Immediate termination. Cannot be caught, blocked, or ignored. Use as last resort.
kill -9 1234SIGHUP (1) — Hangup. Often used to tell daemons to reload their configuration.
kill -HUP $(pidof nginx)SIGSTOP (19) — Pause a process (cannot be caught). Resume with SIGCONT.
kill -STOP 1234SIGCONT (18) — Resume a stopped/paused process.
kill -CONT 1234SIGUSR1 (10) / SIGUSR2 (12) — User-defined signals. Used by applications for custom actions (e.g., log rotation).
kill -USR1 $(pidof nginx)SIGINT (2) — Interrupt (same as Ctrl+C). Graceful stop for interactive programs.
kill -INT 1234SIGQUIT (3) — Quit with core dump (same as Ctrl+). For debugging.
kill -QUIT 1234Common Patterns
kill $(pgrep -f '<pattern>') — Kill processes matching a command-line pattern.
kill $(pgrep -f 'python3 worker.py')kill $(cat <pidfile>) — Kill a process using its PID file.
kill $(cat /var/run/nginx.pid)kill -HUP $(pidof <daemon>) — Reload a daemon's configuration without restarting.
sudo kill -HUP $(pidof nginx)ps aux | grep <pattern> | grep -v grep | awk '{print $2}' | xargs kill — Find and kill processes using a pipeline (classic pattern).
ps aux | grep 'myapp' | grep -v grep | awk '{print $2}' | xargs kill -9kill -TERM <pid> && sleep 5 && kill -0 <pid> && kill -9 <pid> — Graceful kill with fallback: try TERM first, then KILL if still alive.
kill -TERM 1234; sleep 5; kill -0 1234 2>/dev/null && kill -9 1234fuser -k <port>/tcp — Kill the process using a specific TCP port.
fuser -k 8080/tcpfuser -k <file> — Kill all processes using a specific file.
fuser -k /var/log/app.log Conclusion
With kill and its relatives you control processes precisely: for everyday work the default SIGTERM usually does the job, letting a program shut down cleanly – and you can address shell jobs of the current session with kill %1. Reach for kill -9 (SIGKILL) only when a process refuses to respond: it aborts hard, without flushing buffers or releasing locks, which can lead to data loss or corrupted files. Be careful with killall and pkill – they target by name and may accidentally hit the wrong process or several at once; test the pattern first with pgrep or pkill -i. For daemons, kill -HUP is often the right tool to reload the configuration without a restart.
Further Reading
- man7.org: kill(1) – the Linux manual page for the kill command
- Wikipedia: Signal (IPC) – background on Unix signals and their numbers