At one time or another, you must have faced the problems with Linux processes, either process are stuck or are unresponsive completely. Some of the time the process restart also does not work & the only thing that can be done is terminating the process completely, that’s where the kill command comes in handy.

Recommended Read: How to change timezone in Linux

Also Read: Examples on how to use PS COMMAND in Linux

There are many other commands as well that can perform the same operation but kill command is most popular & widely used. Let’s see the syntax for using kill command,

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

kill command

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.