Skip to content

Signals on Linux

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

Every process in Linux listens to signals. These signals are used by the Kernel, by other processes, or by the user to Notify a particular process about a particular event. UNIX guru W. Richard Stevens describes the signals as software interruptions.

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

Each sign has a unique name and a numerical value.

Let’s look at some values and their actions:

TABLE — Most important signs

keys.
**Signal** **Numerical Value** SIGHUP 1 **Action**
Hang-Up or shutdown. 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.
SIGINT 2 It is the signal to stop working. It is triggered, for example, when you press the Ctrl C.
SIGKILL 9Terminate the process unconditionally quickly and drastically. This type of signal can leave open files and corrupted databases. It should be used if the process stops responding or in an emergency.
SIGTERM 15 ends the process in an elegant manner, allowing it to close files and execute its end-of-execution routines.
SIGCONT 18 It is a signal for a process that has been stopped with the SIGSTOP signal so that it can continue to execute.
SIGSTOP 19 It is a signal that can be sent for a process to stop working momentarily. It still exists but is not given any more CPU to execute until it receives the SIGCONT signal.
SIGTSTP 20 Terminates 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.

The understanding of signals is important to know how the system interacts with the processes in execution. The kill and killall commands can be used to send specific signals to a running process.

Most administrators use SIGKILL when stopping a process. However, this signal is very “strong” because it abruptly stops the running process and can leave open files, malfunctioning indexes, and corrupted data. It is best to use the SIGTERM signal, which allows the program to finish elegantly, closing files, indexes, and databases.

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

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

Did you like it?

Share