fbpx Linux Signals: SIGTERM, SIGKILL, SIGHUP and How to Use kill | Certificação Linux

Linux Signals: SIGTERM, SIGKILL, SIGHUP and How to Use kill and trap

📅 12/08/2021 ⏱ 3 min ✍️ Uira Ribeiro
Linuxcommands
Linux Signals: SIGTERM, SIGKILL, SIGHUP and How to Use kill and trap
Exam Pass App — mais de 7.000 questões LPI, offline, em 5 idiomas, disponível no Android e na App Store
Available on
Google Play
Available on
App Store

The "conversation" between the operating system and running programs is through Signals in Linux, which are software interrupts, used to put a program connected to a terminal, on hold, in the background or foreground, and even stop its execution. 

Each process in Linux stays listening for signals. These signals are used by the Kernel, by other processes or by users to notify a specific process about a particular event. The UNIX guru W. Richard Stevens describes signals as software interrupts.

When a signal is sent to a process it takes a specific action depending on the value that this signal carries. 

Each signal has a unique name and a numeric value. 

Let's look at some values and their actions:

TABLE – Most important signals

SignalNumeric ValueAction
SIGHUP1Hang-Up or disconnect. This signal is used automatically when you disconnect from a session or close a terminal. It is also used by server processes to invoke the rereading of the configuration file.
SIGINT2This is the interrupt signal. It is triggered for example when you press the Ctrl C keys.
SIGKILL9Terminate the process unconditionally quickly and drastically. This type of signal can leave open files and corrupted databases. Should be used if the process stops responding or in an emergency.
SIGTERM15Terminate the process gracefully, allowing it to close files and execute its shutdown routines.
SIGCONT18This is a signal for a process that was stopped with the SIGSTOP signal so that it continues to execute.
SIGSTOP19This is a signal that can be sent to a process to stop it from functioning temporarily. It still exists, but no longer receives CPU to execute, until it receives the SIGCONT signal.
SIGTSTP20Terminate execution to continue later. This signal is sent automatically when we use the ctrl-z keys. It is used to put the process in the background.

Linux has over 30 defined signals. Most are used by the Kernel and some by users in specific situations.

Understanding signals is important for knowing how the system interacts with running processes. The kill and killall commands can be used to send specific signals to a running process.

Most administrators when stopping a process use SIGKILL. However, this signal is very "strong", as it makes an abrupt stop in the running process, and can leave open files, malformed indexes, and corrupted data. It is better to use the SIGTERM signal, which allows the program to terminate gracefully, closing files, indexes and databases.

Linux allows users to send signals to running programs through the kill command.

Learn much more about Linux in our online course. You can enroll here. If you already have an account, or want to create one, just log in or create your user here.

Liked it? Share

Uira Ribeiro

Prof. Uirá Ribeiro

Chair do Board do Linux Professional Institute

After years of watching professionals waste hours on simple tasks because they didn't know the right Linux tools, I decided to teach.
Today I'm the author of most of LPI's official Learning Materials and mentor to over 14,000 certified students.

See my full story →

That was just one piece. The course teaches the whole path — from your first command to exam day.

Certificação Linux — a plataforma líder em certificações Linux no Brasil
WhatsApp