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:
- What is the kill Command in Linux?
- What is the Usage of the kill Command in Linux?
- Bonus Tip: Most Used kill Commands in Linux
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:
-s | It is used to specify the signal sent. |
-l | It 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:
Purpose | Command |
---|---|
To reload a process | kill -1 [PID] |
To terminate a process | kill -9 [PID] |
To kill the interrupt produced by the keyboard | kill -2 [PID] |
To stop process | kill 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.
Check our LinkedIn company page