kill Command in Linux | Explained

If you are new to the Linux world and came from the Windows operating system, then you must be familiar with the Task manager. Whenever the operating system gets halted, the conventional approach is to launch the task manager and close that program.

When linux behaves abnormally while dealing with processes, then the easiest way to stop the specified process is by using the kill command to kill it.

In this write-up, the kill command utility in Linux has been explained in detail by covering the following sections:

Let’s start the blog!

What is the kill Command in Linux?

The kill command utility in Linux sends a signal to the system to stop/kill it. The general syntax of using the kill command in Linux is:

General Syntax

$ kill [options] <pid> [...]

Use the PID of the process whose behavior is supposed to be set with the kill command. Different Options can be used with the kill command, but the most used options are:

-sIt is used to specify the signal sent.
-lIt is used to list all the available signals.

For more details on options, use the following command:

$ kill --help

Let’s head over to the examples!

What is the Usage of the kill Command in Linux?

In this section, the usage of the kill command in Linux has been explained with different examples.

Let’s start!

Example 1: How to kill All the Processes in Linux?

To kill all the processes in Linux, use the kill command with its -9 -1 options as shown below:

$ kill -9 -1

This will even shut down the Linux machine.

Example 2: How to Display All the Signals of the kill Command in Linux?

The signals which can be used with the kill command can be displayed on the screen using the command:

$ kill -L

All the signals are displayed with their number of orders.

For example, to kill the command, we can use either SIGKILL or 9, and similarly, to reboot the process, use either SIGHUP or 1.

Example 3:  How to kill a Specific Process?

To kill or handle the behavior of the process with its PID, the PID of the process should be known. To find out the PID, use the “pidof” command as shown below:

$ pidof thunderbird

In the above output, the pidof of the “thunderbird” has been displayed. Now, kill the process of “thunderbird” using the PID with the kill command:

$ kill -9 20186 20103 20010

Doing so, the “thunderbird” will be terminated.

Example 4:  How to Reload the Process in Linux?

We can reload the processes in Linux by using the -1 with the kill command. For example, 1118 is the pid of the mysql, which can be reloaded using the kill command:

$ sudo kill -1 1118

Doing so, Mysql will be reloaded.

Bonus Tip: Most Used kill Commands in Linux

Here, we present a table of the most used variants of the “kill” command in Linux:

PurposeCommand
To reload a processkill -1 [PID]
To terminate a processkill -9 [PID]
To kill the interrupt produced by the keyboardkill -2 [PID]
To stop processkill 17 [PID]

That’s all about this blog.

Conclusion

The kill command is used to pass different signals in Linux to manage the behavior of the processes. Using the kill command, a single process, multiple processes, or all the processes on a Linux system can be terminated. The kill command line utility is quite helpful in managing the load on the RAM of the computer. This write-up has explained the usage of the kill command utility with its different examples in Linux.