Commonly used Signals in Unix
Signals are short messages sent to your program. Each signal has a number assigned to it.
In shell script, we are only interested in signals that can be generated by the user that might prematurely end the script. These
include signals 1, 2, and 3.
Signal 1
Signal 1 is called the hangup signal and is referred to as HUP or SIGHUP in the documentation. This signal is generated when a
user dials into a shell account through a modem and the telephone line is disconnected. When a shell receives this signal, the
default action is to die. The command kill –1
will also send this signal.
Signal 2
Signal 2 is called the interrupt signal and is referred to as INT or SIGINT in the documentation. This signal is generated when
the user types a CTRL+C. When a shell receives this signal, the default action is to die. The command kill –2
will also send this signal.
Signal 3
Signal 3 is called the quit signal and is referred to as SIGQUIT or QUIT in the documentation. This signal is generated when the
user types a CTRL+-\. When a shell receives this signal, the default action is to die and to save a copy of the memory or the
running program in a file called “core”. The core file can sometimes be used to debug a program, but is usually
unneeded and should be removed. The command kill –3
will also send the quit signal.
Signals
The following table summarizes the above information.
Number Generated by this action Generated by this kill
command
1 (HUP) |
Hanging up the modem when dialed in kill -1 |
2 (INT) |
Pressing CTRL+-C kill -2 |
3 (QUIT) |
Pressing CTRL+-\ kill -3 |