kill vs killall – difference and command usage

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 kill and killall commands on Linux. You’ll also see examples of how to use each command.

In this tutorial you will learn:

  • Difference between kill vs killall
  • How to kill processes with kill and killall commands
  • Using kill -9 and killall -9 commands
kill vs killall - difference and command usage
kill vs killall – difference and command usage
Software Requirements and Linux Command Line Conventions
Category Requirements, Conventions or Software Version Used
System Any Linux distro
Software kill, killall
Other Privileged access to your Linux system as root or via the sudo command.
Conventions # – requires given linux commands to be executed with root privileges either directly as a root user or by use of sudo command
$ – 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:

  1. To kill a process on Linux, use the kill command and specify the process ID you are planning to terminate.
    $ kill 1234
    
  2. The killall command 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 killall command.

  3. Note that you can still end multiple processes at once with the normal kill command, but you would need to specify each process ID that you wish to terminate.
    $ kill 1234 1233 1232
    

So, there are two key differences:

  • kill accepts process ID numbers as an argument, and only kills one process at a time (unless you specify multiple process IDs in your command)
  • killall allows us to kill processes by name and will end all processes that have a matching name


Ending processess with kill and killall commands on Linux
Ending processess with kill and killall commands on Linux

kill -9 vs killall -9

By default, kill and 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, kill and 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 kill or killall, you would use the following command syntax:

  1. Forcefully close a process by sending a SIGKILL signal with kill:
    $ kill -9 1234
    
  2. Forcefully close a process or multiple processes by sending a SIGKILL signal with killall:
    $ 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.

Closing Thoughts

In this guide, we learned the difference between the kill and killall commands on Linux. We also saw examples for using each one to send SIGTERM or 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.