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
| Tool | Selects by | Example | Watch out for |
|---|---|---|---|
| kill | PID or -PGID | kill -TERM 4821 | Stale PIDs reused by new processes |
| killall | Exact process name | killall -HUP nginx | Different meaning on Solaris |
| pkill | Regex on name, or -f full cmdline | pkill -f "celery worker" | Patterns matching more than intended |
| pgrep | Same as pkill, prints PIDs | pgrep -af gunicorn | Use it first as a dry run |
| systemctl kill | systemd unit | systemctl kill -s HUP nginx | Signals every process in the unit |
The escalation ladder
- kill -TERM PID: ask nicely, give it time to clean up
- Wait 5-30 seconds (timeout -k or a loop)
- kill -INT or -QUIT if it ignores TERM (QUIT gives a core dump)
- kill -KILL PID only as the last resort
Signalling a process group
Safe habits
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 20Check 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"; fiKill 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 aliceCommon 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.