pkill command sends any specified signal, or by default the termination signal, to processes based on a matching pattern. Similar to the pgrep command, but actually sends a signal instead of printing to stdout. For example, if you start top in one terminal, and then issue pkill top in another terminal, you’ll see that top terminates. The command matched a name pattern rather than a process ID.
Syntax
The syntax of this command is:
# pkill [options] {pattern}
If you encounter the below error while running the pkill command:
pkill: command not found
you may try installing the below package as per your choice of distribution:
OS Distribution | Command |
---|---|
Debian | apt-get install procps |
Ubuntu | apt-get install procps |
Alpine | apk add procps |
Arch Linux | pacman -S procps-ng |
Kali Linux | apt-get install procps |
CentOS | yum install procps-ng |
Fedora | dnf install procps-ng |
Raspbian | apt-get install procps |
pkill Command Examples
1. Kill all processes which match:
# pkill "process_name"
2. Kill all processes which match their full command instead of just the process name:
# pkill -f "command_name"
3. Force kill matching processes (can’t be blocked):
# pkill -9 "process_name"
4. Send SIGUSR1 signal to processes which match:
# pkill -USR1 "process_name"
5. Kill the main `firefox` process to close the browser:
# pkill --oldest "firefox"