Recommended Read: How to change timezone in Linux
Also Read: Examples on how to use PS COMMAND in Linux
Syntax
# kill -signal pid(process_id)
It provides a lot of options i.e. signal to handle the processes. Let’s discuss a little more about kill Command with the help of some examples.
Examples
List all the kill signals available
Kill has a lot of signals available to manage the running or stuck processes & we should know how to check & use them. To get the complete list of all kill signals, the command is
# kill -l
So there are 63 signals that we can use with kill command but most of them are not used at all. The mostly used signals are,
-
1 (HUP) – Reload a process
-
9 (KILL) – Kill a process
-
15 (TERM) – Gracefully stop the process
Stop a process
To stop a process, we must know the process id which can be obtained by using the ps command,
# ps -ef | grep haproxy
Or you can also use another command to get the process id,
# pidof haproxy
Once you have the process id, we can use it to terminate/reload or gracefully stop the process. You can use the kill command the following 3 ways,
# kill -9 pid
# kill -SIGKILL pid
# kill -KILL pid
You can either use the signal number, signal name or signal name without SIG.
Reload a process
With kill command, we can also reload the process, again we would first need the process id first. We can then use the following command to reload the process,
# kill -1 pid
# kill -SIGHUP pid
# kill -HUP pid
We can use either of the three commands.
Gracefully stop a process
To gracefully stop a process, we can use the either of the following commands,
# kill -15 pid
# kill -SIGTERM pid
# kill -TERM pid
We end this tutorial on how to use kill in Linux. Please do let us know if you have any questions, queries or suggestions using the comment box below.
If you think we have helped you or just want to support us, please consider these:-
Connect to us: Facebook | Twitter | Linkedin
TheLinuxGURUS are thankful for your continued support.
The post Learn to use KILL COMMAND in Linux appeared first on The Linux GURUS.