Полезная информация

Practical UNIX & Internet Security

Practical UNIX & Internet SecuritySearch this book
Previous: C.2 Creating ProcessesAppendix C
UNIX Processes
Next: C.4 The kill Command
 

C.3 Signals

Signals are a simple UNIX mechanism for controlling processes. A signal is a 5-bit message to a process that requires immediate attention. Each signal has associated with it a default action; for some signals, you can change this default action. Signals are generated by exceptions, which include:

The system default may be to ignore the signal, to terminate the process receiving the signal (and, optionally, generate a core file), or to suspend the process until it receives a continuation signal. Some signals can be caught - that is, a program can specify a particular function that should be run when the signal is received. By design, UNIX supports exactly 31 signals. They are listed in the files /usr/include/signal.h and /usr/include/sys/signal.h. Table 27.4 contains a summary.

Table C.6: UNIX Signals

Signal Name

Number[7]

Key

Meaning[8]

SIGHUP

1

Hangup (sent to a process when a modem or network connection is lost)

SIGINT

2

Interrupt (generated by CTRL-C (Berkeley UNIX) or RUBOUT (System V).

SIGQUIT

3

*

Quit

SIGILL

4

*

Illegal instruction

SIGTRAP

5

*

Trace trap

SIGIOT

6

*

I/O trap instruction; used on PDP-11 UNIX

SIGEMT

7

*

Emulator trap instruction; used on some computers without floating-point hardware support

SIGFPE

8

*

Floating-point exception

SIGKILL

9

!

Kill

SIGBUS

10

*

Bus error (invalid memory reference, such as an attempt to read a full word on a half-word boundary)

SIGSEGV

11

*

Segmentation violation (invalid memory reference, such as an attempt to read outside a process's memory map)

SIGSYS

12

*

Bad argument to a system call

SIGPIPE

13

Write on a pipe that has no process to read it

SIGALRM

14

Timer alarm

SIGTERM

15

Software termination signal (default kill signal)

SIGURG

16

@

Urgent condition present

SIGSTOP

17

+!

Stop process

SIGTSTP

18

+

Stop signal generated by keyboard

SIGCONT

19

@

Continue after stop

SIGCHLD

20

@

Child process state has changed

SIGTTIN

21

+

Read attempted from control terminal while process is in background

SIGTTOU

22

+

Write attempted to control terminal while process is in background

SIGIO

23

@

Input/output event

SIGXCPU

24

CPU time limit exceeded

SIGXFSZ

25

File size limit exceeded

SIGVTALRM

26

Virtual time alarm

SIGPROF

27

Profiling timer alarm

SIGWINCH

28

@

tty window has changed size

SIGLOST

29

Resource lost

SIGUSR1

30

User-defined signal #1

SIGUSR2

31

User-defined signal #2

[7] The signal number varies on some systems.

[8] The default action for most signals is to terminate.

Key:

*

If signal is not caught or ignored, generates a core image dump.

@

Signal is ignored by default.

+

Signal causes process to suspend.

!

Signal cannot be caught or ignored.

Signals are normally used between processes for process control. They are also used within a process to indicate exceptional conditions that should be handled immediately (for example, floating-point overflows).


Previous: C.2 Creating ProcessesPractical UNIX & Internet SecurityNext: C.4 The kill Command
C.2 Creating ProcessesBook IndexC.4 The kill Command