The standard or Unix signals

As can be seen from the output of kill, all supported signals on the platform are shown; the first 31 of these (on your typical Linux box) are called the standard or Unix signals. Unlike the real-time signals that follow, each standard/Unix signal has a very specific name, and, as you might guess, purpose.

(Worry not; we shall discuss the real-time signals, numbers 34 to 64, in the next chapter).

The table you will see shortly, essentially reproduced from the man page on signal(7), summarizes the standard (Unix) signals in the following column order: the signal's symbolic name, integer value(s), the default action taken upon delivery to a process, and a comment describing the signal. 

The default action column has the following types: the default action of the signal handler is to:

  • Terminate: Terminate the process.
  • Term&Core: Terminate the process and emit a core dump. (A core dump is, essentially, a snapshot of the process's dynamic segments, the data and stack segments, at the time when the (fatal) signal was delivered). This terminate and core dump action occurs when the kernel sends a fatal signal to a process. The implication is that the process has done something illegal (buggy); an exception is the SIGQUIT signal: we get a core dump when SIGQUIT is delivered to a process.
  • Ignore: Ignore the signal.
  • Stop: Process enters the stopped (frozen/suspended) state (represented by T in the output of ps -l).
  • Continue: Continue execution of a previously stopped process.

Refer to the table Standard or Unix signals:

Signal

Integer

value

Default

action

Comment

SIGHUP

1

Terminate

Hang up detected on controlling terminal or death of controlling process​

SIGINT

2

Terminate

Interrupt from keyboard : ^C

SIGQUIT

3

Term&Core

Quit from keyboard : ^

SIGILL

4

Term&Core

Illegal Instruction

SIGABRT

6

Term&Core

Abort signal from abort(3)​

SIGFPE

8

Term&Core

Floating-point exception​

SIGKILL

9

Terminate

(Hard) kill signal

SIGSEGV

11

Term&Core

Invalid memory reference

SIGPIPE

13

Terminate

Broken pipe: write to pipe with no readers; see pipe(7)

SIGALRM

14

Terminate

Timer signal from alarm(2)

SIGTERM

15

Terminate

Termination signal (soft kill)

SIGUSR1

30,10,16

Terminate

User-defined signal 1

SIGUSR2

31,12,17

Terminate

User-defined signal 2

SIGCHLD

20,17,18

Ignore

Child stopped or terminated

SIGCONT

19,18,25

Continue

Continue if stopped

SIGSTOP

17,19,23

Stop

Stop process

SIGTSTP

18,20,24

Stop

Stop typed at terminal : ^Z

SIGTTIN

21,21,26

Stop

Terminal input for background process

SIGTTOU

22,22,27

Stop

Terminal output for background process

At times, the second column, the signal's integer value, has three numbers. Well, it's like this: the numbers are architecture-(meaning CPU) dependent; the middle column represents the value for the x86 architecture.
Always use the symbolic name of the signal in code (such as SIGSEGV), including scripts, and never the number (such as 11). You can see that the numeric value changes with the CPU, which could lead to non-portable buggy code!

What if the system admin needs to urgently kill a process? Yes, its quite possible that, while logged into an interactive shell, time is very precious and an extra couple of seconds may make a difference. In such cases, typing kill -9 is better than kill -SIGKILL, or even kill -KILL. (The previous point is with regard to writing source code).

Passing the signal number to kill -l causes it to print the signal's symbolic name (albeit in a shorthand notation). For example:
$ kill -l 11
SEGV

The preceding table (and, as a matter of fact the following table as well) reveal that, with two exceptions, all the signals have a special purpose. Scanning the comment column reveals it. The exceptions are SIGUSR1 and SIGUSR2 these are general purpose signals; their use is left entirely to the imagination of the application designers.

Further, the man page informs us that the following signals (shown in this table) are newer and included in the SUSv2 and POSIX.1-2001 standards:

Signal Integer
Value
Default
Action
Comment
SIGBUS 10,7,10 Term&Core Bus error (bad memory access)
SIGPOLL Terminate Pollable event (Sys V). Synonym for SIGIO
SIGPROF 27,27,29 Terminate Profiling timer expired
SIGSYS 12,31,12 Term&Core Bad system call (SVr4); see also seccomp(2)
SIGTRAP 5 Term&Core Trace/breakpoint trap
SIGURG 16,23,21 Ignore Urgent condition on socket (4.2BSD)
SIGVTALRM 26,26,28 Terminate Virtual alarm clock (4.2BSD)
SIGXCPU 24,24,30 Term&Core CPU time limit exceeded (4.2BSD); see prlimit(2)
SIGXFSZ 25,25,31 Term&Core File size limit exceeded (4.2BSD); see prlimit(2)
 Newer standard or Unix signals

A few remaining (not so common) signals are further mentioned by the same man page (signal(7)). Take a look if you are interested.

It's important to note that, out of all the signals mentioned, only two of them cannot be caught, ignored or blocked: the SIGKILL and the SIGSTOP. This is because the OS must guarantee a way to kill and/or stop a process.

..................Content has been hidden....................

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