The Linux Crash Course series on Learn Linux TV will teach you an important Linux-related skill or concept in each video. This time around, Jay will go over the kill command (which thankfully isn’t as violent as it sounds).
Basic Usage
Let’s get started!
On the screen right now is a very common example of using the kill command to kill a process. I’m not going to have you execute this command, I’m just showing it as an example.
kill -9 44533
So first, we have the kill command. What the kill command does is send what’s called a signal to a process. A signal causes an application to respond in a particular way, such as asking a program to close or re-read its configuration file.
In this case, we’re sending signal 9 to process id 44533. As you may or may not know, every process running on a Linux system has a unique number associated with it, known as the process ID or “PID”.
If I were to actually execute this command, and assuming I actually did have something running with this PID, then it would cause the process to terminate.
This is useful if you have a process that for some reason or another, won’t close. So this variation of the command is often found on many tutorials and howto’s, as it’s a popular method of closing an unresponsive program.
On camera
One thing that’s confusing about the kill command for some people, is the name of the command itself. Kill. The name would have you think that killing processes is all the kill command does. Not only that, the most common example of the kill command was the one I just gave. So you’d be forgiven if you weren’t aware of other things that the command can do.
For example, consider this command:
kill -3 43312
In this case, I’m sending signal 3 to a process, which causes it to quit cleanly and also create a file for debugging. We’re not going to get into the latter, but I use this command on my end every now and then to restart GNOME Shell on my PC. If my desktop becomes unresponsive, I connect to my machine remotely via SSH and execute this example against the process ID of GNOME Shell, which causes it to quit – but it will also respawn itself and then my entire desktop session is saved without me losing any work. And this is just one example.
Before we go any further though, I wanted to throw another command at you – the pidof command. This isn’t directly related to the kill command, but the pidof command can be used to find out what the PID is of a process.
pidof vim
Moving on, I’ve mentioned signals a few times now, and we understand that we can send one of these so-called signals to a process in order to get it to do something. If you want to get a list of all the signals you could possibly send a process, run the following:
kill -L
I can’t go over all of these, but what I will do is cover some of the more common ones that are used.
1 SIGHUP Re-read config
2 SIGINT Interrupt the process
3 SIGQUIT Quit and create a dump file
9 SIGKILL Forcefully terminate the process
15 SIGTERM Politely ask for termination, allowing cleanup (default)
Signals can be referred to by their number or their “SIG” prefix. So in the case of our previous examples, we’ve talked about signals 3 and 9 so far.
Signal 15 is the default, which also terminates a process but it basically informs the process that it needs to close, rather than forcing it to do so. This enables the process to execute its closing commands, giving it a chance to free resources. This is always preferred if you want to terminate a process, signal 9 is a last resort.
So, if you want to terminate a process, the best place to start is by asking it nicely:
kill 59494
Since Signal 15 is the default, and that signal asks a process to close cleanly, we can ommit the signal altogether.
Another aspect of the kill command to know is the fact that you can use it against multiple processes at once. You simply type command followed by a space-separated list of processes to send a signal to. So if we had three unresponsive processes, we might run:
kill -9 55848 54939 59493
While it’s probably convenient to be able to target multiple processes, if you’re trying to kill multiple processes then I would think your server might be having a bigger problem – multiple unresponsive processes can be a sign of something else. But who knows, you might have a use-case for killing multiple processes some day.
I mentioned earlier that you can refer to a signal by it’s “SIG” prefix or it’s number. So going back to our kill -9 example, we can also write it like this:
kill -s SIGKILL 59494
In this case though, it’s simpler to just type the signal number.
kill -9 59494


