In this article we are going to show you how to use kill Command in Linux opperating system. If you want to learn about kill command in Linux then this post is ideal for you.
In Linux, kill command is a built in command that is used to terminate the process manually. It is most commonly used command to terminate the process. It terminates processes using Process ID number (PID) and sends a signal to a process which terminates the process.
How to Use the kill
Command
Use the type command to show all locations on your system containing kill
:
$ type -a kill
kill is a shell builtin
kill is /bin/kill
Syntax of kill command:
In the Linux, the basic syntax of the kill
command is show as below:
kill [OPTIONS] [PID]...
Kill command sends a signal to specified processes or process groups and when no signal is specified, each tool sends 15
(TERM
).
Below are the most commonly used signals in Linux :
1
(HUP
): it is used to reload a process.9
(KILL
): it is used to kill a process.15
(TERM
): it is used to gracefully stop a process.
You can list of all available signals in the Linux using kill -l
option.
These signals are specified in three different ways:
- using a number (e.g. -1)
- with the “SIG” prefix (e.g. -SIGHUP)
- without the “SIG” prefix (e.g. -HUP)
$ kill -l
Terminate a Processes:
Before terminate a process with the kill
command, you will need to find the process PID of a running process. You can find PID using different commands such as top
, ps
, pidof
, and pgrep
.
For an example, if Google Chrome browser is become unresponsive and you want to kill the browser process then first find the PID of Google Chrome using the pidof command:
$ pidof google-chrome
The above command will display the all Google Chrome processes:
Output
5561 2021 1992 1685
After find the Google Chrome processes PIDs, terminate all of them using command below:
$ kill -9 5561 2021 1992 1685
OR
$ kill -9 $(pidof google-chrome)
Reloading Processes
You can also use kill
command to send the HUP
signal that tells the processes to reload its settings.
For an example, if you wish to reload the Nginx server settings then you will need to send a signal to the master process. The nginx.pid
file is located at /var/run
that contains the process ID of the Nginx master process. You can use the cat command to find out the master PID:
cat /var/run/nginx.pid
Output
12265
Now reload the Nginx settings using below command:
sudo kill -1 10235
That’s all
If you face any error and issue in above steps , please use comment box below to report.
If our tutorials helped you, please consider buying us a coffee. We appreciate your support!
Thank you for your support.