The killall command in Linux allows you to kill the process using the process name. Sure, you can do the same with the kill command but it requires a specific option to use the process name instead of the PID. So in this tutorial, I will guide you through how you can get the most out of the killall command by covering the following points:Syntax and available options for the killall command Practical examples of the killall command Let’s start with the first one.How to use the killall command in Linux To use any command to its maximum potential, it is recommended to get started with the syntax and the same goes for the kill command:killall [OPTIONS] nameHere, [OPTIONS]: Optional flags (also known as options) which are used to modify the default behaviour of the killall command. For example, you can use the -I option to perform a case-insensitive search.name: The name of the process which you want to terminate.Now, let’s take a look at the available options with the killall command:
Option
Description
-e
Require an exact match for the process name.
-I
Match process names case-insensitively.
-i
Interactively ask for confirmation before killing processes.
-q
Suppress error messages if no processes are found.
-r
Interpret the process name as a regular expression.
-s SIGNAL
Specify the signal to be sent to terminate the processes (default is SIGTERM).
-u USER
Kill processes owned by the specified user.
-v
Report if the signal was successfully sent (verbose output).
-w
Wait for all killed processes to die.
Practical examples of the killall command In this section, I will share some helpful examples of the killall command to help you better understand the applications of the killall command.1. Kill a specific process By far this is the most useful application of the killall command where you append the process name to the killall command and it terminates the process. Yes, it’s that simple! Here’s how you do it:killall process-nameFor example, if I want to kill htop, then I’ll use the following command:killall htop2. Send a specific kill signal By default, the killall command uses the SIGTERM termination signal which is enough for the most part but there are times when you expect different behaviour while terminating the process.The killall command allows you to choose from multiple termination signals. To use multiple termination signals use the -S flag along with the termination signal as shown here: killall -s <Termination_Signal> processFor example, if I want to kill the apache2 process using the SIGKILL signal, then I’ll be using the following:killall -s SIGKILL apache23. Kill processes interactively You can also use the killall command to kill the process interactively which will prompt you to ask for confirmation to kill the process. To kill process interactively, you can use the -i option as shown here:killall -i processFor example, here, I have used the interactive prompt while killing the htop process:killall -i htop4. Kill process owned by a specific userWhen you try killing a process owned by another user, it gives you an error saying “Operation not permitted”:Unable to kill process owned by another userTo kill a process owned by a specific user, you can use the -u flag to specify the username along with the process name as shown:sudo killall -u <username> processFor example, if I want to kill the htop process owned by the user team, then I’ll use the following:sudo killall -u team htop5. Kill process using regular expression If you want to kill multiple processes at once, then using a regular expression could be a great option. To use the regex, you have to use the -r flag as shown here:kill -r REGEXFor example, If I want to terminate all processes whose names start with “http”, such as “httpd” or “http-server”, I’ll use the following command:killall -r ‘http.*’More ways to kill (processes)Linux provides multiple ways you can kill processes. For example, if you want to kill a process on a specific port, then you can refer to the given guide:Kill Process Running on a Specific Port in LinuxWant to kill the processes running on specific ports? No need to know the process ID or name. You can terminate a process based on the port number it is using.If you are wondering about the difference between the kill and killall commands, here’s your answer:Kill vs Killall: Difference Between the Two Linux CommandsBoth kill and killall commands are used for force stopping (killing) processes in Linux. Learn the difference between the two similar commands.I hope you will find this tutorial helpful and if you have any queries, feel free to leave us a comment.