man-pages/man3p/signal.3p

152 lines
4.6 KiB
Plaintext

.\" Copyright (c) 2001-2003 The Open Group, All Rights Reserved
.TH "SIGNAL" P 2003 "IEEE/The Open Group" "POSIX Programmer's Manual"
.\" signal
.SH NAME
signal \- signal management
.SH SYNOPSIS
.LP
\fB#include <signal.h>
.br
.sp
void (*signal(int\fP \fIsig\fP\fB, void (*\fP\fIfunc\fP\fB)(int)))(int);
.br
\fP
.SH DESCRIPTION
.LP
Use
of this function is unspecified in a multi-threaded process.
.LP
The \fIsignal\fP() function chooses one of three ways in which receipt
of the signal number \fIsig\fP is to be subsequently
handled. If the value of \fIfunc\fP is SIG_DFL, default handling for
that signal shall occur. If the value of \fIfunc\fP is
SIG_IGN, the signal shall be ignored. Otherwise, the application shall
ensure that \fIfunc\fP points to a function to be called
when that signal occurs. An invocation of such a function because
of a signal, or (recursively) of any further functions called by
that invocation (other than functions in the standard library), is
called a "signal handler".
.LP
When a signal occurs, and \fIfunc\fP points to a function, it is implementation-defined
whether the equivalent of a:
.sp
.RS
.nf
\fBsignal(\fP\fIsig\fP\fB, SIG_DFL);
\fP
.fi
.RE
.LP
is executed or the implementation prevents some implementation-defined
set of signals (at least including \fIsig\fP) from
occurring until the current signal handling has completed. (If the
value of \fIsig\fP is SIGILL, the implementation may
alternatively define that no action is taken.) Next the equivalent
of:
.sp
.RS
.nf
\fB(*func)(sig);
\fP
.fi
.RE
.LP
is executed. If and when the function returns, if the value of \fIsig\fP
was SIGFPE, SIGILL, or SIGSEGV or any other
implementation-defined value corresponding to a computational exception,
the behavior is undefined. Otherwise, the program shall
resume execution at the point it was interrupted. If the signal occurs
as the result of calling the \fIabort\fP(), \fIraise\fP(), \fIkill\fP(),
\fIpthread_kill\fP(), or \fIsigqueue\fP() function, the
signal handler shall not call the \fIraise\fP() function.
.LP
If the signal occurs other than as the result of calling \fIabort\fP(),
\fIraise\fP(), \fIkill\fP(), \fIpthread_kill\fP(), or \fIsigqueue\fP(),
\ the behavior is undefined if the signal handler refers to any
object with static storage duration other than by assigning a value
to an object declared as volatile \fBsig_atomic_t\fP, or if
the signal handler calls any function in the standard library other
than one of the functions listed in \fISignal Concepts\fP . Furthermore,
if such a call fails, the value of \fIerrno\fP is
unspecified.
.LP
At program start-up, the equivalent of:
.sp
.RS
.nf
\fBsignal(\fP\fIsig\fP\fB, SIG_IGN);
\fP
.fi
.RE
.LP
is executed for some signals, and the equivalent of:
.sp
.RS
.nf
\fBsignal(\fP\fIsig\fP\fB, SIG_DFL);
\fP
.fi
.RE
.LP
is executed for all other signals \ (see \fIexec\fP).
.SH RETURN VALUE
.LP
If the request can be honored, \fIsignal\fP() shall return the value
of \fIfunc\fP for the most recent call to \fIsignal\fP()
for the specified signal \fIsig\fP. Otherwise, SIG_ERR shall be returned
and a positive value shall be stored in \fIerrno\fP.
.SH ERRORS
.LP
The \fIsignal\fP() function shall fail if:
.TP 7
.B EINVAL
The \fIsig\fP argument is not a valid signal number or an attempt
is made to catch a signal that cannot be caught or ignore a
signal that cannot be ignored.
.sp
.LP
The \fIsignal\fP() function may fail if:
.TP 7
.B EINVAL
An
attempt was made to set the action to SIG_DFL for a signal that cannot
be caught or ignored (or both).
.sp
.LP
\fIThe following sections are informative.\fP
.SH EXAMPLES
.LP
None.
.SH APPLICATION USAGE
.LP
The \fIsigaction\fP() function provides a more comprehensive and reliable
mechanism
for controlling signals; new applications should use \fIsigaction\fP()
rather than
\fIsignal\fP().
.SH RATIONALE
.LP
None.
.SH FUTURE DIRECTIONS
.LP
None.
.SH SEE ALSO
.LP
\fISignal Concepts\fP , \fIexec\fP() , \fIpause\fP() , \fIsigaction\fP()
, \fIsigsuspend\fP() , \fIwaitid\fP() , the Base Definitions volume
of IEEE\ Std\ 1003.1-2001, \fI<signal.h>\fP
.SH COPYRIGHT
Portions of this text are reprinted and reproduced in electronic form
from IEEE Std 1003.1, 2003 Edition, Standard for Information Technology
-- Portable Operating System Interface (POSIX), The Open Group Base
Specifications Issue 6, Copyright (C) 2001-2003 by the Institute of
Electrical and Electronics Engineers, Inc and The Open Group. In the
event of any discrepancy between this version and the original IEEE and
The Open Group Standard, the original IEEE and The Open Group Standard
is the referee document. The original Standard can be obtained online at
http://www.opengroup.org/unix/online.html .