Related
Quick Links
Software interrupts on Linux and Unix systems are made via signals.
Here’s how they work.
What Is aLinux Signal?
We all understand a red light means that we have to stop walking or driving.
For example, one could send a red traffic light sign to a program by simply issuing a
signal.
The basic Linux signals all have a number (1-30+).
After a little while, a proficient Linux user will generally know one or more of these.
One can select a process by pressing the cursor up/down and then send a signal by using F9.
Note that whenever we speak of process or program, the words can be interchanged at will.
A number of signals can be captured and redirected by the process, whereas others cannot.
We subsequently killed that background process using
, where the
stands for
.
We check the process list by grepping for the PID
.
Let’s evaluate the same with
, i.e.
where
is the process we want to terminate.
We had to press enter to trigger/show the termination message (as explained above).
We can see that the program terminated correctly again.
However, this time, while invisible for this particular example (read on!
), internally inside the
program code, things went a little different.
In this case (using
i.e.
to terminate the process), the
process was notified and had the opportunity to internally handle the signal.
The first time, we used
and the second time we used
to stop the
process.
We immediately notice how the output returns
in the first (
action) instance.
For the second attempt (using
), we see the output
instead; the program self-terminated.
Why is this important?
Consider larger programs; in this instance, we were just terminating a simple
command.
There was no data being handled, no traffic being sent back/forth, etc.
In other words, it crashed.
The program terminated, or betterwas interruptedby the
signal that was sent.
We request the exit code and confirm that once again the exit code is different from the previous signals.
(which is the case for many shell scripts, especially when managing servers or automated environments).
Another often-used keyboard sequence is
.
To learn more about process management, seeBash Process Termination Hacks.