signal.2: Clarify System V vs BSD semantics for signal()

Reported-by: Reuben Thomas <rrt@sc3d.org>
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
This commit is contained in:
Michael Kerrisk 2013-02-09 03:34:59 +01:00
parent 73d3ac53ef
commit 3659da5b70
1 changed files with 19 additions and 6 deletions

View File

@ -31,7 +31,7 @@
.\" various sections. .\" various sections.
.\" 2008-07-11, mtk: rewrote and expanded portability discussion. .\" 2008-07-11, mtk: rewrote and expanded portability discussion.
.\" .\"
.TH SIGNAL 2 2012-05-05 "Linux" "Linux Programmer's Manual" .TH SIGNAL 2 2013-02-09 "Linux" "Linux Programmer's Manual"
.SH NAME .SH NAME
signal \- ANSI C signal handling signal \- ANSI C signal handling
.SH SYNOPSIS .SH SYNOPSIS
@ -185,6 +185,12 @@ was invoked by the delivery of a signal,
the disposition of the signal would be reset to the disposition of the signal would be reset to
.BR SIG_DFL , .BR SIG_DFL ,
and the system did not block delivery of further instances of the signal. and the system did not block delivery of further instances of the signal.
This is equivalent to calling
.BR sigaction (2)
with the following flags:
sa.sa_flags = SA_RESETHAND | SA_NODEFER;
System V also provides these semantics for System V also provides these semantics for
.BR signal (). .BR signal ().
This was bad because the signal might be delivered again This was bad because the signal might be delivered again
@ -192,15 +198,22 @@ before the handler had a chance to reestablish itself.
Furthermore, rapid deliveries of the same signal could Furthermore, rapid deliveries of the same signal could
result in recursive invocations of the handler. result in recursive invocations of the handler.
BSD improved on this situation by changing the semantics of BSD improved on this situation, but unfortunately also
signal handling changed the semantics of the existing
(but, unfortunately, silently changed the semantics .BR signal ()
when establishing a handler with interface while doing so.
.BR signal ()).
On BSD, when a signal handler is invoked, On BSD, when a signal handler is invoked,
the signal disposition is not reset, the signal disposition is not reset,
and further instances of the signal are blocked from and further instances of the signal are blocked from
being delivered while the handler is executing. being delivered while the handler is executing.
Furthermore, certain blocking system calls are automatically
restarted if interrupted by a signal handler (see
.BR signal (7)).
The BSD semantics are equivalent to calling
.BR sigaction (2)
with the following flags:
sa.sa_flags = SA_RESTART;
The situation on Linux is as follows: The situation on Linux is as follows:
.IP * 2 .IP * 2