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 1234

kill -9 <pid> — Send SIGKILL (force kill, cannot be caught or ignored).

kill -9 1234

kill -SIGTERM <pid> — Send SIGTERM by name (same as kill without flags).

kill -SIGTERM 1234

kill -<signal> <pid> — Send a specific signal by number or name.

kill -HUP 1234

kill <pid1> <pid2> <pid3> — Send SIGTERM to multiple processes.

kill 1234 1235 1236

kill -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 -l

killall — By Process Name

killall <name> — Send SIGTERM to all processes matching the exact name.

killall nginx

killall -9 <name> — Force kill all processes matching the name.

killall -9 php-fpm

killall -i <name> — Interactive mode: ask for confirmation before killing each process.

killall -i python3

killall -u <user> — Kill all processes owned by a specific user.

killall -u testuser

killall -u <user> <name> — Kill processes by name owned by a specific user.

killall -u www-data php-fpm

killall -o <time> <name> — Kill only processes older than the specified time.

killall -o 1h php-fpm

killall -y <time> <name> — Kill only processes younger than the specified time.

killall -y 5m my-script

killall -w <name> — Wait for all killed processes to die before returning.

killall -w nginx

killall -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 firefox

pkill -9 <pattern> — Force kill processes matching the pattern.

pkill -9 chrome

pkill -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 guest

pkill -t <tty> — Kill all processes on a specific terminal.

pkill -t pts/3

pkill -P <ppid> — Kill all child processes of a parent PID.

pkill -P 1234

pkill -x <name> — Match the exact process name only (no partial matches).

pkill -x python3

Finding Process IDs

pgrep <pattern> — Find PIDs of processes matching a pattern (companion to pkill).

pgrep nginx

pgrep -l <pattern> — Show PIDs and process names.

pgrep -l php

pgrep -a <pattern> — Show PIDs and full command lines.

pgrep -a python

pgrep -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 nginx

Important Signals

SIGTERM (15) — Graceful termination. The process can catch it and clean up. Default signal.

kill -TERM 1234   # or just: kill 1234

SIGKILL (9) — Immediate termination. Cannot be caught, blocked, or ignored. Use as last resort.

kill -9 1234

SIGHUP (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 1234

SIGCONT (18) — Resume a stopped/paused process.

kill -CONT 1234

SIGUSR1 (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 1234

SIGQUIT (3) — Quit with core dump (same as Ctrl+). For debugging.

kill -QUIT 1234

Common 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 -9

kill -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 1234

fuser -k <port>/tcp — Kill the process using a specific TCP port.

fuser -k 8080/tcp

fuser -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

  • ps – list running processes and their PIDs
  • top – monitor processes and resource usage live
  • jobs – list background jobs of the current shell