What are linux signals and its types.

What are Linux Signals?

Linux signals are the form of interprocess communications which are used to send asynchronous notification a process or to a specific thread within the same process in order to notify it of an event that occurred.

It is just like the way a Signal is. Conveying message and instruction to a certain process.

Whenever a Signal is sent, the normal flow of execution is interrupted and it is delivered to signal. For example: Whenever user press CTRL + C, it sends a kill signal to a process due to which it’s normal flow of execution is interrupted and is delivered to the type of signal which is sent.

In Linux, all the signal name starts with the keyword SIG. SIGTERM, SIGKILL is the type of signals which are used commonly used in Linux.

In Linux, each signal has a numeric value associated with it which can be used to send a specific type of signal just by their value number. The whole term can always be used, but it is always convenient to send a signal to its number as it is more time-consuming. For ex: Value associated with KILL Signal is -9. So to send a KILL signal to a process one can use both of these commands

kill -9 0710

kill -SIGKILL 0710

One can find the process id of a process by using ps command and then can send the desired signal to the process. Interrupt it, kill it, all up to the need.

When ever you send a signal to a process, it tells the kernel what to do with it. Depending upon the signal desired action is performed. Sometimes some signals can be ignored by the kernel, but hardware signals like SIGSTOP or SIGKILL can not be ignored by the kernel.

There are many types of signals in Linux which are used to send the various type of interrupts to a process or to a specific thread. 

Types of Linux Signals

Signal             Value            Action       Comment

──────────────────────────────────────────────────────────────
SIGHUP        1       Term    Hangup detected on controlling 
                              terminal
SIGINT        2       Term    Interrupt from keyboard
SIGQUIT       3       Core    Quit from keyboard
SIGILL        4       Core    Illegal Instruction
SIGABRT       6       Core    Abort signal from abort(3)
SIGFPE        8       Core    Floating point exception
SIGKILL       9       Term    Kill signal
SIGSEGV      11       Core    Invalid memory reference
SIGPIPE      13       Term    Broken pipe: write to pipe with no 
                              readers                              
SIGALRM      14       Term    Timer signal from alarm(2)
SIGTERM      15       Term    Termination signal
SIGUSR1   30,10,16    Term    User-defined signal 1
SIGUSR2   31,12,17    Term    User-defined signal 2
SIGCHLD   20,17,18    Ign     Child stopped or terminated
SIGCONT   19,18,25    Cont    Continue if stopped
SIGSTOP   17,19,23    Stop    Stop process
SIGTSTP   18,20,24    Stop    Stop typed at terminal
SIGTTIN   21,21,26    Stop    Terminal input for background 
                              process
SIGTTOU   22,22,27    Stop    Terminal output for background 
                              process

 

Though most of the Signals can be caught and blocked, SIGSTOP and SIGKILL are the two signals which cannot be caught and blocked.One should always think twice before sending these signals.

Also if a process catches a signal, it means that it includes code that will take appropriate action when the signal is received. If the signal is not caught by the process, the kernel will take default action for the signal.

  • Add Your Comment