Signals

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.

Available signals

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:

  • Term: Terminate
  • Core: Terminate the process and dump core
  • Ign: Ignore the signal
  • Stop: Stop the process

Depending upon what kind of signal it is, any of the following actions can be taken:

  • A signal can be ignored by a process, which means no action will be taken. Most of the signals can be ignored, except 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.
  • A signal can be handled by writing a signal handler code specifying the required action to be taken after a particular signal is received.
  • Each signal has a default action, so let the signal perform the default action; for example, terminate the process in case the SIGKILL signal is sent.

To know all signals and its corresponding value, use the kill command with the–l option:

$ kill -l
Available signals

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
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.227.209.207