Managing processes is one of the core tasks in Linux system administration. Improper process termination can lead to data loss, system instability, or frozen applications. This guide will help you understand how to safely and effectively stop processes, what different termination signals mean, and how to follow best practices when doing so.
In Linux, processes communicate through a mechanism called signals. A signal is a message sent to a process by the operating system or another process to notify it of an event or request an action.
Common Signals Used for Termination:
(To see the complete list of all available signals, open a Linux terminal and run the command kill -l)
👉 Rule of thumb: always start with SIGTERM and use SIGKILL only as a last resort.
kill Command: Your Primary ToolBasic Syntax:
kill [-s sigspec | -n signum | -sigspec] pid
Where:
Main Principles:
ps, top, htop).systemctl stop over kill.Graceful Termination (Recommended)
> kill 1234
> kill -TERM 1234
> kill -s TERM 1234
> kill -n 15 1234
Forceful Termination (Last Resort)
> kill -9 1234
> kill -KILL 1234
> kill -s KILL 1234
> kill -n 9 1234
Reload Configuration
> kill -HUP 1234
> kill -s HUP 1234
> kill -n 1 1234
You can use a “zero signal” to check if a process is running — without killing it.
> kill -0 PID
Return values:
💡 Pro tip: kill -0 does not send any signal — it only checks process existence and permissions!
Since the command itself doesn't print any output, you can check its result using the echo $? command, which displays the exit status of the last executed command, or use it directly in a shell script with conditional statements (if/else):
if kill -0 1234 2>/dev/null; then
echo "Process 1234 is running"
else
echo "Process 1234 not found"
fi
pkillpkill terminates processes by matching a pattern (regular expression).
This makes it a flexible tool for finding and killing processes not only by exact name but also by parts of the command line.
# Graceful termination by name
> pkill -TERM firefox
# Forceful termination
> pkill -KILL firefox
# Match full command line
> pkill -f "python my_script.py"
# Interactive mode (asks for confirmation)
> pkill -i firefox
# Regex pattern with full command line
> pkill -f "^node" # Processes where command starts with "node"
> pkill -f "node.*" # Processes with "node" in command line
killallkillall stops processes by exact name only — simple and safer when you know the exact program name.
# Graceful termination of all 'firefox' processes
> killall firefox
# Forceful termination
> killall -9 firefox
# Kill all 'firefox' processes owned by a specific user
> killall -u username firefox
To terminate a process group (a parent process and all its children):
> kill -TERM -1234
Here, -1234 is the Process Group ID (PGID).
This command stops the parent and all of its spawned processes.
To terminate all processes owned by a specific user:
> pkill -u username
> killall -u username