What's the difference between kill and killall commands?
Both kill and killall commands are used for force stopping (killing) processes in Linux. Learn the difference between the two similar commands.
From Linux forums to Linux memes, you'll come across two commands for force ending programs in Linux; kill and killall.
While many Linux users are aware of the kill command, not many people know and use the killall command.
And it could be confusing for people anyway. Both commands have similar sounding name and similar purpose (to end processes).
So, what's the difference between kill and killall? Which command should you use and in which case should you use them?
Difference between kill and killall commands
The kill command works on the process ID (PID) and it kills the processes for which you provide the PIDs. On the other hand, the killall command works on the process name and it kills all the processes with the given process names. For example, if there are three instances of
mysqld running, the killall will kill all three of them with
killall mysqld whereas you have to provide PIDs of all three instances to kill command as
kill PID1 PID2 PID3.
In simpler words, kill command works with PID (often individual PID) and killall command works with process name and kills all the processes with the process name.
Let me show that in action.
I start three instances of a program called evince and send it to the background (it keeps on running but gives back the control to terminal).
evince & evince & evince &
Now, I have three programs running with the process name evince but with different process IDs.
To force stop the process with the kill command, you need to provide the PIDs of the desired processes.
However, supply the process name to the killall command and it will kill all the running instances with that process names.
Take a look at the screenshot below to see all the commands in action:
Which one should you use? Kill or Killall?
Since the kill command works with individual processes, it is safer. After all, before launching the killall command, you should make sure that there aren't any similarly named processes running that you don't want to kill.
I hope you have a clear picture of kill and killalll commands now. Feel free to drop a question or suggestion.