Categories: How-To

Signals on Linux [Basic Guide]

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 9 Terminate 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

Uirá Endy Ribeiro

Uirá Endy Ribeiro is a Software Developer and Cloud Computing Architect with a 23-year career. He has master's degrees in computer science and fifteen IT certifications and is the author of 11 books recognized in the IT world market. He is also Director at Universidade Salgado de Oliveira and Director of the Linux Professional Institute - LPI Director's Board.

Uirá Endy Ribeiro

Uirá Endy Ribeiro is a Software Developer and Cloud Computing Architect with a 23-year career. He has master's degrees in computer science and fifteen IT certifications and is the author of 11 books recognized in the IT world market. He is also Director at Universidade Salgado de Oliveira and Director of the Linux Professional Institute - LPI Director's Board.

Recent Posts

Sudo command on Linux (privilege scale) [Basic Guide]

The sudo command on Linux executes a given command as if it were another user.…

2 years ago

SS command on Linux (investigate the network) [Basic Guide]

The ss command on Linux is extremely useful for investigating sockets, providing various information about…

2 years ago

Free Linux command (memory usage) [Basic Guide]

Free Linux command shows the amount of total memory in use and available, as well…

2 years ago

Linux while command (loop – while) [Basic Guide]

The shell has structures for testing conditions and executing certain program sequences several times (loop),…

2 years ago

Linux fstab file (disk mount setup) [Basic Guide]

The /etc/fstab file stores the configuration of which devices should be mounted and what is…

2 years ago

Netcat command on Linux (Swiss network knife) [Basic Guide]

The Netcat Command in Linux or nc is a utility used to do “almost anything”…

2 years ago

This website uses cookies.