Snippets Linux / Command / Kill

Command Kill

By Marcelo Fernandes Jul 13, 2017

Linux Command Kill

Send a signal to one or more processes (usually in order to "kill" a process)
But this is not all about it. Its real purpose is to send signals to processes. Although most of the time we are going to send signals that are intended to tell the process to go away, if the program is well designed, it will listen the operating system

Basic Usage:
kill [options] <pid>
Where options are:
<pid>, -<signal>, -s <signal>, --signal <signal>

How To:

In order to summarize, there are 4 signals that are mostly used.
Signal # Name Description
1 HUP "Hang up" signal. Programs can listen for this signal, or better: They must be programmed in order to do so. Most daemons are programmed to re-read their configurations (restart), when they receive this signal. It's likely to be the safest kill signal as it shouldn't obstruct anything.
2 INT This is the same as pushing CTRL+C in any program that is executing. It will basically send a signal to the process to interrupt it. Keep in mind that you may loose data if you use this signal.
9 KILL The kernel will turn off the process without sending any signal to it. This is the "toughest" and most unsafe way of killing a process, it should only be used when you can't kill a process anyhow.
15 TERM The standard signal, if you don't explicitly say which signal you want, this is gonna be sent. It basically tells the process to stop whatever it's doing and end itself. It should be very safe, but it's better to stick with the HUP signal.
Signals can be specified either by name (e.g. -HUP or -SIGHUP) or by number (e.g. -1) or by option -s.

# Basic Usage
kill -HUP masterpid

# Killing up all processes that has the word gunicorn in it.
ps aux
kill -1 $(pgrep gunicorn)


Quick commands:

kill -HUP masterpid