We have all faced unresponsive applications while using any operating system, including Linux. These applications often have background processes that use up the system’s resources without your knowledge. When an application becomes unresponsive, it is often impossible to close it manually. Don’t worry because using the “killall” command of Linux, you can kill all the instances of a specific application. However, it must be understood before it should be used.
This guide explains the “killall” command of Linux in detail.
- What is the killall Command in Linux?
- How Does the killall Command Work?
- How to Fix the killall Command not Found in Linux?
- How to Use the killall Command in Linux?
- Difference Between the killall and kill Commands in Linux
Let’s start rolling with the killall command of Linux.
What is the killall Command in Linux?
The “killall” in Linux is a command-line utility for killing, suspending/stopping, and continuing a single or multiple processes. It is like the kill command, with a few differences that we will explain later. The killall command can suspend or eliminate all other processes except for itself. It is handy when you want to close multiple instances of a running application or program forcefully.
How Does the killall Command Work?
The “killall” command in Linux acts as the emergency rescue service that can quickly terminate a single or all the processes of a specific application or program. It works by issuing a signal to the processes that match the name or the process ID. This signal can forcefully terminate the process or allow the process to close itself gracefully.
Let’s dig into the details of the killall command in Linux.
Syntax
killall [Options] [Name]
Here,
- The “killall” invokes the command.
- The “Options” specify the behavior of how the “killall” command will behave.
- The “Name” tells the “killall” the name of the process on which the command will work.
How to Fix the killall Command not Found in Linux?
The killall command comes pre-installed with the package called “psmisc”, but some users reported getting the error “kill command not found”. This issue arises when the “psmisc” package is missing from your system. To install the “psmisc” package in which the killall command is included, use the following commands (based on your distribution):
sudo apt install psmisc #Ubuntu/Debian
sudo yum install psmisc #CentOS/RHEL
sudo dnf install psmisc #Fedora/Rocky Linux
The above snippet confirms the installation of the “psmisc” package on Ubuntu 22.04.
Options/Flags of the killall Command in Linux
The options/flags of the killall command in Linux include the following:
-e or –exact | Use this option to input the exact name. It works best with long process names, as the killall command works by matching process names by default. |
-I or –ignore-case | Use this option to make the killall command ignore the case for the process names. The killall command is case-sensitive. |
-g or –process-group | Use this option to make the killall command to eliminate the processes belonging to a specific group. The groups in Linux are the processes working together in a session. |
-y or –younger-than | Use this option to make the kill command to eliminate the processes younger than the specified time. |
-o or –older-than | Use this option to make the kill command to eliminate the processes older than the specified time. |
-i or –interactive | Use this option to make the kill command ask for confirmation before eliminating the process. |
-l or –list | Use this option to view a list of all known signal names discussed below this section. |
-q or –quiet | Use this option to prevent the killall command from making the complaints if no process was eliminated. |
-r or –regexp | Use this option to make the killall command match the process-name pattern according to the regular expressions. |
-s or –signal SIGNAL | Use this option to make the killall command send the specified signal. The default signal is the SIGTERM signal; details of the signals you can use are explained after this section. |
-u or –user USERNAME | Use this option to make the killall command eliminate the process(es) from the specified USERNAME. |
-v or –verbose | Use this option to make the killall command display a notification if the process was successfully eliminated. |
-V or –version | Use this option to view the version and copyright information of the killall utility. |
-w or –wait | Use this option to make the killall command check & wait until the process is eliminated. This process is done every second and may continue forever if the signal is ignored or |
-n or -ns PID | Use this option to make the killall command match processes belonging to the namespace of the specified PID. |
-Z or –context REGEXP | Use this command to make the killall command eliminate the processes having security context and it should match with the given extended regular expression pattern. |
Signals
In Linux, users can send the following signals to the processes per the requirements. Additionally, the OS can automatically send these signals according to the conditions (input & output):
SIGNAL | Number | Description |
---|---|---|
HUP or SIGHUP | 1 | The HUP signal disconnects the child process from its origin/parent process. |
INT or SIGINT | 2 | It is the same as using the CTRL + C keys to interrupt and stop the process. The process can ignore this signal. |
QUIT or SIGQUIT | 3 | It works the same as the INT but makes the process create a core dump. |
ILL or SIGILL | 4 | It is sent by the system when a process tries to perform some illegal actions. This halts the process. |
TRAP or SIGTRAP | 5 | The TRAP signal is sent when a condition for the process to continue is met. It is used for debugging purposes. |
ABRT or SIGABRT | 6 | The ABRT is the abort signal that tells the process to kill itself. |
BUS or SIGBUS | 7 | The system sends the BUS signal when the process attempts to use fake physical addresses or there are some memory errors. It is sent due to the bus error. |
FPE or SIGFPE | 8 | The FPE signal is sent by the system when a process tries illegal operations like dividing by zero. This kills the process. |
KILL or SIGKILL | 9 | The KILL signal instantly kills the program. It is a powerful signal that the process cannot ignore. Using this signal, the process does not clean up the temporary data or save any unsaved progress. |
USR1 or SIGUSR1 | 10 | The USR1 is the user-defined condition defined using the C or C++ programming languages. |
SEGV or SIGSEGV | 11 | When an application/process commits a segmentation violation, the system sends the SEGV signal to that application/process. |
USR2 or SIGUSR2 | 12 | The USR2 is an indicator of the user-defined condition. |
PIPE or SIGPIPE | 13 | The PIPE signal is sent when writing to a pipe that does not have a reader function. It is treated as an error. |
ALRM or SIGALRM | 14 | The ALRM signal is sent after the clock timer has expired. |
TERM or SIGTERM | 15 | The TERM signal tells the process to shut itself down gracefully.Simply put, this signal gives the process time to save the data before gracefully exiting. The process can ignore this signal. |
STKFLT or SIGSTKFLT | 16 | It is the stack fault mapped to the SIGUNUSED. |
CHLD or SIGCHLD | 17 | The CHLD signal is sent when the child’s process is paused, stopped, or resumed. |
CONT or SIGCONT | 18 | The CONT signal resumes the process after it is paused by the SIGTSTP or SIGSTOP signal. |
STOP or SIGSTOP | 19 | The STOP signal halts the process or pauses its execution. The process/program cannot ignore this signal. |
TSTP or SIGTSTP | 20 | The TSTP signal works like pressing the CTRL + Z keys on the terminal. It temporarily stops the process, which can be resumed using the CONT or SIGCONT signal. |
TTIN or SIGTTIN | 21 | The process receives a TTIN signal when it tries to read from a tty or computer terminal. |
TTOU or SIGTTOU | 22 | The process receives a TTIN signal when it tries to write to a tty or computer terminal. |
URG or SIGURG | 23 | The system sends the URG signal to the process when the process urgently needs to read the data. The same happens when the data to be read is too large. |
XCPU or SIGXCPU | 24 | The XCPU signal is sent by the system to the process when the process has used the CPU for more than the allotted time. It is a warning for the process to save the CPU’s time and save the progress before being killed. |
XFSZ or SIGXFSZ | 25 | All file systems have a specified limit on how large a file can be. The XFSZ signal is sent to the process when it attempts to violate the specified file limit. |
VTALRM or SIGVTALRM | 26 | The system sends the SIGVTALRM to the process when the allotted CPU time has elapsed. It acts as the virtual alarm and kills the process. |
PROF or SIGPROF | 27 | A timer measures the time a process uses the CPU. When the timer expires, the PROF signal is sent/forwarded to the process and eliminates/kills it. |
WINCH or SIGWINCH | 28 | The WINCH or Window Change signal to the process when it controls the window size or attempts to alter it. |
POLL or SIGPOLL | 29 | The POLL signal is sent to the process when it triggers an asynchronous event for the input/output operations. |
PWR or SIGPWR | 30 | The system sends the PWR signal to all the processes when a power cut/failure is detected. |
SYS or SIGSYS | 31 | The system sends the SYS signal to the process for compatibility reasons. For instance, a process that gives an invalid system call will get this signal from the system. |
Note: To view a list of processes on your Linux system, use the ps Command (highly recommended).
How to Use the killall Command in Linux?
The killall command in Linux requires arguments/options or signals, which are explained above. Let’s understand its use with the help of examples.
Example 1: Kill All Instances of a Process Via killall Command in Linux
The “killall process_name” command sends a SIGTERM signal to the stated process. This causes the process to terminate immediately:
killall firefox
Once the above command is executed, it will immediately check for all the processes named “firefox” and kill all its instances. The killall command in Linux is handy when you want to kill a process and its instances without finding the PID.
Example 2: Kill All Instances of a Process Via killall Command for a Specific User in Linux
If you want to kill/eliminate all the processes for a particular user, use the “killall -u USERNAME” command. It will kill all processes associated with the specified username.
Let’s kill all the processes for the user named “Linuxuser” using the below command:
killall -u Linuxuser
However, this command should be used only when a system is not responding because executing it will kill all the processes and log the user out.
Example 3: Making the killall Command Ignore the Case-Sensitivity
The killall command is case-sensitive by default, but you can make it ignore the case-sensitivity using the “-I” or “–ignore-case” option/flag of the killall command. In the below command, we have tried to killall FireFox with and without the “-I”:
killall FireFox
killall -I FireFox
Here you can see that the killall command did not find the FireFox process, but once we used the “-I” option/flag, it killed all instances of Firefox.
Example 4: Using the killall Command in Linux to Kill the Processes Based on Running Time
The killall command enables you to kill the processes in Linux based on their running time. The options to do that include “-y” or “–younger-than” and “-o” or “–older-than”.
Let’s use them individually:
killall -y 1m nano
The above command kills the processes started by the “nano editor” younger than one minute.
To kill a process older than the specified time using the killall, use this command:
killall -o 1m nano
The above command kills all the associated processes started by the “nano editor” older than one minute.
The units of time that are used with the killall command of Linux include the following:
- The “s” is for seconds.
- The “m” is for minutes.
- The “h” is for hours.
- The “w” represents the weeks.
- The “M” is for months.
- The “y” is for the years.
Example 5: Making the killall Command Ask Before Killing a Process
If you want to kill specific processes that belong to the same group, use the “-i” flag. This flag also makes the killall command prompt to confirm the killing of the process. It is illustrated as follows:
killall -i nano
As seen above, the killall command did ask whether to kill a process. If you enter “Y”, the process will be killed, while “N” will keep the process running.
Example 6: Make the killall Command Wait for the Process to Finish the Job and Then Exit
The “-w” flag/option of the killall command allows the targeted process to complete the job and exit while making the killall command wait. It may take a long time because you never know when the process’s job will be complete and it will be ready to exit.
Let’s make the killall command wait for the nano process to finish the job and then exit:
killall -w nano
In the above snippet, the terminal is waiting and you cannot execute any other command. To make it stop waiting, press the “CTRL + C” keys.
Example 7: Using Signals With killall Command in Linux
By default, the killall command sends the “SIGTERM” signal to the process. But you can send other/additional signals using the “-s” or “–signal” option/flag. Let’s try using the “TSTP” or “SIGTSTP” to the nano process to stop its execution temporarily:
killall -s TSTP nano
By executing the above command, the “-s TSTP” temporarily stops the nano process.
Example 8: Using Signals With the killall Command in Linux to Force Kill a Process
The “-9” option/flag sends/forwards the “SIGKILL” signal to the process and immediately kills it. One should be careful while using this because it will not let the process save any data and the program attached to the process may misbehave. Let’s kill the nano editor (running in the background) via the following command:
killall -9 nano
The above output shows that all instances of the nano command are instantly killed and it did not let the process save any unsaved data.
Difference Between the killall and kill Commands in Linux
The killall command can kill/eliminate multiple processes, and you can use the process’s name to do so, while the kill command can only kill a single process at a time and requires a “PID” for the process to kill. More about the kill command can be learned.
That’s all for the killall command in Linux.
Final Words
Using the killall command in Linux, users can kill or terminate the processes. It includes several options/flags that improve its functionality. The killall command can efficiently work with the signals. Although like the kill command, it can kill multiple processes, and users can pass the process name as an argument. In short, the killall command terminates the specified processes.