The killall command sends any specified signal, or the default termination signal, to all processes matching the name specified. Similar to pkill but has a few functional differences, such as matching process names exactly. Here is the syntax:
# killall [-u user] [-signal] name...
To demonstrate, we will start a couple of instances of the sleep program and then terminate them.
$ sleep 500 & [1] 18801 $ sleep 600 & [2] 18802
$ killall sleep [1]- Terminated sleep [2]+ Terminated sleep
Remember, as with kill; you must have superuser privileges to send signals to processes that do not belong to you.
If you encounter the below error while running the killall command:
killall: command not found
you may install the below package as per your choice of distribution:
OS Distribution | Command |
---|---|
Debian | apt-get install psmisc |
Ubuntu | apt-get install psmisc |
Alpine | apk add psmisc |
Arch Linux | pacman -S psmisc |
Kali Linux | apt-get install psmisc |
CentOS | yum install psmisc |
Fedora | dnf install psmisc |
Raspbian | apt-get install psmisc |
killall Command Examples
1. To kill all the specified commands:
# killall
2. To list all known signals:
# killall -l # killall --list
3. Do not complain if no processes were killed:
# killall -q # killall --quiet
4. To send the specified signal instead of SIGTERM:
# killall -s 9 bash # killall --signal 9 bash
5. To kill processes owned by particular user:
# killall -u mike
6. To set to verbose mode:
# killall -v # killall --verbose
7. To display the version:
# killall -V # killall --version
8. To specify to wait for all the killed processes to die:
# killall -w # killall --wait
9. To kill processes with specified security context:
# killall -Z # killall --context
10. Interactively ask for confirmation before termination:
# killall -i process_name
11. Terminate a process using the SIGINT (interrupt) signal, which is the same signal sent by pressing `Ctrl + C`:
# killall -INT process_name
12. Force kill a process:
# killall -KILL process_name
Conclusion
Commands often used in conjunction with ps are kill and killall. When running ps, we saw that there is a column that displays PID, short for process ID. If a process isn’t running right, hanging, or we just want to end it, one way is using the kill command. Simply pass it the PID, for example, given a PID of 123:
# kill 123
If you want to match the process by name instead of PID, you can use killall, for example, if Firefox was frozen and we wanted to force quit:
# killall firefox