This article will discuss a difference between kill vs killall commands. Killing processes on a Linux is an essential thing for admins and users to know. At some point, you’ll encounter an application or services that hangs and freezes, and you’ll need to kill the process to exit it.
The Linux command line offers a few different ways for us to kill processes. Having multiple tools for the job, as is common on Linux, is convenient but creates some confusion as they all have a little functional overlap.
In this tutorial, we’ll explain the difference between the
killall commands on Linux. You’ll also see examples of how to use each command.
In this tutorial you will learn:
- Difference between
- How to kill processes with
|Requirements, Conventions or Software Version Used
|Any Linux distro
|Privileged access to your Linux system as root or via the
|# – requires given linux commands to be executed with root privileges either directly as a root user or by use of
$ – requires given linux commands to be executed as a regular non-privileged user
kill vs killall – What’s the difference?
As is obvious from the names,
kill will terminate a process and
killall can terminate multiple processes simultaneously.
The best way to understand the difference is by looking at some examples:
- To kill a process on Linux, use the
killcommand and specify the process ID you are planning to terminate.
$ kill 1234
killallcommand works a little differently by accepting the name of a process to end, and by killing all processes that match the name you specify.
$ killall firefox
In this example, all of the processes named “firefox” would be terminated. It doesn’t matter if you have only 1 Firefox window open, or 50. They’ll all be closed after running the
- Note that you can still end multiple processes at once with the normal
killcommand, but you would need to specify each process ID that you wish to terminate.
$ kill 1234 1233 1232
So, there are two key differences:
killaccepts process ID numbers as an argument, and only kills one process at a time (unless you specify multiple process IDs in your command)
killallallows us to kill processes by name and will end all processes that have a matching name
kill -9 vs killall -9
killall will try to stop a process as gracefully as possible. Both will send a SIGTERM signal to the specified process, and that instructs the process to shut down. It’s a polite way to end a running process, and gives the application or service time to wrap things up first – like finish writing to log files, close opened connections that were spawned by the process, etc.
The only problem with this is that a stubborn program may ignore the SIGTERM signal. This occurs especially in a process that is frozen or “hung up.” However,
killall can be used to send a lot of different signals to a process, and can even force the most stubborn ones to close with a SIGKILL signal.
To send a SIGKILL signal with either
killall, you would use the following command syntax:
- Forcefully close a process by sending a SIGKILL signal with
$ kill -9 1234
- Forcefully close a process or multiple processes by sending a SIGKILL signal with
$ killall -9 firefox
When possible, you should send an ordinary SIGTERM signal to a process that you wish to end. Immediately killing a service with a SIGKILL signal is effective every time and will give you instant results, but can cause future problems since the process didn’t get a chance to shut down properly.
In this guide, we learned the difference between the
killall commands on Linux. We also saw examples for using each one to send
SIGKILL signals to one or more processes. For further reading, check out our article on the pkill command, which works similarly to
killall but doesn’t require exact name matching.