kill Command Examples

There are times when you encounter a process consuming a major chunk of resources and want to stop (or kill) it as soon as possible.

But the next question in your mind is how you kill a process. Well, the answer is to use the kill command.

In this tutorial, I will walk you through using the kill command. I will start with the syntax and later introduce practical examples.

How to use the kill command in Linux

You'll only be able to get the most out of the kill command when you know the syntax and that is why I'm starting this tutorial by sharing the syntax of the kill command:

kill [option] [signal] PID

Here,

  • [option]: it is used to fine-tune the default behavior of the kill command.
  • [signal]: here's where you specify what kill signal you want to use to kill the process.
  • PID: process ID of the process that you want to kill.

First, let's take a look at the available options with the kill command:

Option Description
-s Specify the signal to send by name or number (e.g., -s SIGINT or -s 2). This option allows you to send a specific signal to the process instead of the default SIGTERM signal.
-q Sends the signal using sigqueue(3) instead of kill(2), allowing an additional integer value to be sent along with the signal.
-l List all signal names and their corresponding values. This option provides a list of all available signals, along with their numerical values.
-L List all signal names in a nice format. Similar to the -l option, it displays the signal names and their descriptions in a more human-readable format.

Now, let's take a look at available signals with the kill command:

Signal Name Signal Value Description
SIGHUP 1 Hangup signal, used to restart or reload processes.
SIGINT 2 Interrupt signal, sent when you press Ctrl+C.
SIGQUIT 3 Quit signal, used to create a core dump of a process.
SIGILL 4 An illegal instruction signal, sent when a process tries to execute an illegal instruction.
SIGTERM 15 Termination signal, the default signal sent by the kill command.
SIGKILL 9 Kill signal, a forceful signal that immediately terminates the process.
SIGSTOP 19 Stop signal, used to pause or suspend a process.
SIGCONT 18 Continue signal, used to resume a suspended process.
SIGTSTP 20 Terminal stop signal, sent when you press Ctrl+Z.
SIGCHLD 17 Child signal, sent to a parent process when a child process terminates or stops.

But if you don't specify the kill signal while executing the kill command, it will utilize SIGTERM signal to terminate the process.

💡
The kill command works on the process ID (PID). There are ways to get the PID of a process. Please read about it.

Practical examples of the kill command

In this section, I will walk you through some practical examples of the kill command to give you an idea of how it can be used in day-to-day tasks.

1. Killing a process

To kill a process using the kill command, all you have to do is specify the PID to the kill command and it will terminate the process:

kill <PID>

For example. here, I wanted to kill Slack Desktop with PID 78210:

kill 78210

Also, if you want to kill multiple processes at once, you specify their PIDs separated by space as shown here:

kill PID1 PID2 PIDn

2. Killing a process by specifying the kill signal

For the most part, the default kill signal will get the job done but what if you want to use a specific signal? You use the -s flag.

Here's how to do it:

kill -s <SIGNAL-NAME/SIGNAL-NUMBER> PID

For example, here, I used the SIGKILL signal to kill PID 3532:

kill -s SIGKILL 3532

3. Listing available kill signals

To list available kill signals, use the -L flag as shown here:

kill -L

But if you look closely, the above output repeats the kill signals.

To tackle this, you can use the standalone version of the kill signal to list available kill signals:

/usr/bin/kill -L

4. Finding the kill signal name using the number

If you have a kill signal number in mind, it can be traced to its name using the -l flag:

kill -l <Signal-number>

For example, if I want to know the name of the kill signal numbered 18, I'd use the following:

kill -l 18

Wrapping Up...

In this tutorial, I went through how you can use the kill command starting from the basic syntax, available options, popular kill signals, and some practical examples.

If you want to know more about using different termination signals, refer to our detailed guide on how to use different kill signals with the kill command:

How to use SIGINT and other Termination Signals in Linux
Terminating executing process is more than just kill -9. Here are some of the prominent termination signals and their usage.

I hope you will find this guide helpful.