A signal is a software interrupt to notify processes that an external event has occurred. In a normal execution, processes keeps running as expected. Now, for some reason, a user may want to cancel a running process
. When the process is started from a terminal, it will terminate when we hit the Ctrl + c keys or run the kill
command.
When we press Ctrl + c keys while process is running in a terminal, a signal SIGINT
is generated and sent to the process running in foreground. Also, when the kill
command is called on process, the SIGKILL
signal is generated and the process is terminated.
Among all available signals, we will discuss the frequently used signals here:
Signal name |
Value |
Default Action |
Description |
---|---|---|---|
SIGHUP |
1 |
Term |
This signal is used to Hangup or death of controlling process |
SIGINT |
2 |
Term |
This signal is used to interrupt from keyboard like ctrl + c, ctrl + z |
SIGQUIT |
3 |
Core |
This signal is used to quit from keyboard |
SIGILL |
4 |
Core |
It is used to for Illegal instruction |
SIGTRAP |
5 |
Core |
This signal is used to trace or breakpoint trap |
SIGABRT |
6 |
Core |
It is used to abort signal |
SIGFPE |
8 |
Core |
Floating point exception |
SIGKILL |
9 |
Term |
Process terminates immediately |
SIGSEGV |
11 |
Core |
Invalid memory reference |
SIGPIPE |
13 |
Term |
Broken pipe |
SIGALRM |
14 |
Term |
Alarm signal |
SIGTERM |
15 |
Term |
Terminate the process |
SIGCHLD |
17 |
Ign |
Child stopped or terminated |
SIGSTOP |
19 |
Stop |
This signal is used to stop the process |
SIGPWR |
30 |
Term |
Power failure |
In the preceding table, we mentioned the signal name and value. Any of them can be used while referring to a signal. The meaning of terms used in the Default action section are as follows:
Depending upon what kind of signal it is, any of the following actions can be taken:
SIGKILL
and SIGSTOP
. The SIGKILL
and SIGSTOP
signals can't be caught, blocked, or ignored. This allows the kernel to kill or stop any process at any point of time.SIGKILL
signal is sent.To know all signals and its corresponding value, use the kill
command with the–l
option:
$ kill -l
The kill
command also provides a way to convert a signal number to a name when used in the following way:
kill -l signal_number $ kill -l 9 KILL $ kill -l 29 IO $ kill -l 100 # invalid signal number gives error bash: kill: 100: invalid signal specification
To send a signal to process(es), we can use the kill
, pkill
, and kilall
commands:
$ kill -9 6758 # Sends SIGKILL process to PID 6758 $ killall -1 foo # Sends SIGHUP signal to process foo $ pkill -19 firef # Sends SIGSTOP signal to processes' name beginning with firef
18.227.209.207