kill, killall and pkill: Sending Linux Signals the Right Way

Use kill, killall, pkill and pgrep to signal processes by PID, name or pattern, target process groups, and escalate from SIGTERM to SIGKILL safely.

Published November 27, 2026

Despite the name, the kill command does not necessarily kill anything. It sends a signal, and SIGTERM (a polite request) is just the default. Linux gives you several tools that differ in how they select processes: kill uses PIDs, killall uses exact names, and pkill uses patterns. Choosing the right one avoids nasty surprises such as stopping every Python process on a shared server.

The concept

kill PID sends SIGTERM to one process. kill -SIGNAL PID sends any signal by name or number (kill -HUP 1234, kill -s USR1 1234, kill -9 1234). A negative PID targets a whole process group: kill -TERM -1234 signals every process in group 1234, which is how you stop a pipeline or a shell script together with its children.

killall NAME signals every process whose command name matches exactly. pkill PATTERN matches a regular expression against process names, or against full command lines with -f. pgrep uses the same matching but only prints PIDs, which makes it the perfect dry run before pkill. On some non-Linux Unix systems (such as Solaris), killall literally kills all processes, so be careful when moving between systems.

Choosing a tool

ToolSelects byExampleWatch out for
killPID or -PGIDkill -TERM 4821Stale PIDs reused by new processes
killallExact process namekillall -HUP nginxDifferent meaning on Solaris
pkillRegex on name, or -f full cmdlinepkill -f "celery worker"Patterns matching more than intended
pgrepSame as pkill, prints PIDspgrep -af gunicornUse it first as a dry run
systemctl killsystemd unitsystemctl kill -s HUP nginxSignals every process in the unit

The escalation ladder

  1. kill -TERM PID: ask nicely, give it time to clean up
  2. Wait 5-30 seconds (timeout -k or a loop)
  3. kill -INT or -QUIT if it ignores TERM (QUIT gives a core dump)
  4. kill -KILL PID only as the last resort
Escalate gradually so applications can shut down cleanly.

Signalling a process group

kill -TERM -4800negative = groupprocess group 4800shell pipelinebash scriptPID 4800curlPID 4801jqPID 4802
A negative PID delivers the signal to every member of the process group.

Safe habits

pgrep -af gunicorn
2301 /srv/app/venv/bin/gunicorn app:app -w 4
2307 /srv/app/venv/bin/gunicorn app:app -w 4
pkill -HUP -o gunicorn # oldest = the master; reloads workers
kill 99999
bash: kill: (99999) - No such process
timeout -k 10 30 ./long-job.sh # TERM at 30 s, KILL 10 s later
Dry-run with pgrep, signal the master only, and enforce deadlines with timeout.

Practical examples

Graceful stop with a timeout, then force

A reusable shell function.

stop_pid() {
  local pid=$1 t=${2:-15}
  kill -TERM "$pid" 2>/dev/null || return 0
  for _ in $(seq "$t"); do kill -0 "$pid" 2>/dev/null || return 0; sleep 1; done
  echo "still alive after ${t}s, sending KILL"; kill -KILL "$pid"
}
stop_pid 4821 20

Check a process exists without signalling it

Signal 0 performs only the permission and existence check.

if kill -0 "$PID" 2>/dev/null; then echo "running"; else echo "gone"; fi

Kill everything a user is running

Useful when cleaning up after a departed user or a runaway job.

pgrep -u alice -l          # review first
pkill -TERM -u alice
sleep 10; pkill -KILL -u alice

Common mistakes

  • pkill python on a shared host, stopping other people's and system processes.
  • Using pkill -f with a short pattern that also matches your own shell or the pkill command line.
  • Saving a PID in a file and killing it days later after the PID has been reused.
  • Killing a child worker when the master process should be signalled to manage its workers.
  • kill -9 on a database server, risking recovery time or corruption.

Key takeaways

  • kill sends signals by PID; killall by exact name; pkill and pgrep by pattern.
  • Always run pgrep with the same arguments before pkill.
  • Use negative PIDs to signal whole process groups.
  • Escalate TERM → wait → KILL; timeout -k automates it.

FAQ

Why is it called kill if it sends any signal?

Historically its main use was terminating processes, and the default signal terminates. The name stuck even though it is a general signal-sending tool.

What does kill -0 do?

Nothing is delivered. It checks whether the process exists and whether you have permission to signal it.

How do I safely stop a systemd service?

Use systemctl stop. It sends the configured KillSignal (SIGTERM by default) to the unit, waits TimeoutStopSec, then sends SIGKILL to anything left.

More Linux articles