237 lines
8.4 KiB
HTML
237 lines
8.4 KiB
HTML
<HTML><HEAD><TITLE><signal.h></TITLE></HEAD><BODY BGCOLOR="#FFFFFF">
|
|
|
|
<H1><A NAME="<signal.h>"><CODE><signal.h></CODE></A></H1><HR>
|
|
|
|
<P><CODE>
|
|
#define <A HREF="#SIGABRT"><B>SIGABRT</B></A>
|
|
<I><integer constant expression >= 0></I><BR>
|
|
#define <A HREF="#SIGFPE"><B>SIGFPE</B></A>
|
|
<I><integer constant expression >= 0></I><BR>
|
|
#define <A HREF="#SIGILL"><B>SIGILL</B></A>
|
|
<I><integer constant expression >= 0></I><BR>
|
|
#define <A HREF="#SIGINT"><B>SIGINT</B></A>
|
|
<I><integer constant expression >= 0></I><BR>
|
|
#define <A HREF="#SIGSEGV"><B>SIGSEGV</B></A>
|
|
<I><integer constant expression >= 0></I><BR>
|
|
#define <A HREF="#SIGTERM"><B>SIGTERM</B></A>
|
|
<I><integer constant expression >= 0></I><BR>
|
|
#define <A HREF="#SIG_DFL"><B>SIG_DFL</B></A>
|
|
<I><address constant expression></I><BR>
|
|
#define <A HREF="#SIG_ERR"><B>SIG_ERR</B></A>
|
|
<I><address constant expression></I><BR>
|
|
#define <A HREF="#SIG_IGN"><B>SIG_IGN</B></A>
|
|
<I><address constant expression></I><BR>
|
|
int <A HREF="#raise"><B>raise</B></A>(int sig);<BR>
|
|
typedef <I>i-type</I>
|
|
<A HREF="#sig_atomic_t"><B>sig_atomic_t</B></A>;<BR>
|
|
void (*<A HREF="#signal"><B>signal</B></A>(int sig,
|
|
void (*func)(int)))(int);
|
|
</CODE></P>
|
|
|
|
<P>Include the standard header <B><CODE><signal.h></CODE></B>
|
|
to specify how the program handles
|
|
<B><A NAME="signals">signals</A></B> while it executes. A signal can
|
|
report some exceptional behavior within the program, such as division
|
|
by zero. Or a signal can report some asynchronous event outside the
|
|
program, such as someone striking an interactive attention key on
|
|
a keyboard.</P>
|
|
|
|
<P>You can report any signal by calling
|
|
<A HREF="#raise"><CODE>raise</CODE></A>. Each implementation
|
|
defines what signals it generates (if any) and under what circumstances
|
|
it generates them. An implementation can define signals other than
|
|
the ones listed here. The standard header
|
|
<CODE><signal.h></CODE> can define
|
|
additional macros with names beginning with <CODE>SIG</CODE> to specify
|
|
the values of additional signals.
|
|
All such values are integer constant expressions >= 0.</P>
|
|
|
|
<P>You can specify a
|
|
<B><A NAME="signal handler">signal handler</A></B> for each signal.
|
|
A signal handler is a function that the target environment
|
|
calls when the corresponding signal occurs.
|
|
The target environment suspends execution of the program
|
|
until the signal handler returns or calls
|
|
<A HREF="setjmp.html#longjmp" tppabs="http://ccs.ucsd.edu/c/setjmp.html#longjmp"><CODE>longjmp</CODE></A>. For maximum
|
|
portability, an asynchronous signal handler should only:</P>
|
|
|
|
<UL>
|
|
<LI>make calls (that succeed) to the function
|
|
<A HREF="#signal"><CODE>signal</CODE></A>
|
|
|
|
<LI>assign values to objects of type <I>volatile</I>
|
|
<A HREF="#sig_atomic_t"><CODE>sig_atomic_t</CODE></A>
|
|
|
|
<LI>return control to its caller
|
|
</UL>
|
|
|
|
<P>If the signal reports an error within the program (and the signal
|
|
is not asynchronous), the signal handler can terminate by calling
|
|
<A HREF="stdlib.html#abort" tppabs="http://ccs.ucsd.edu/c/stdlib.html#abort"><CODE>abort</CODE></A>,
|
|
<A HREF="stdlib.html#exit" tppabs="http://ccs.ucsd.edu/c/stdlib.html#exit"><CODE>exit</CODE></A>, or
|
|
<A HREF="setjmp.html#longjmp" tppabs="http://ccs.ucsd.edu/c/setjmp.html#longjmp"><CODE>longjmp</CODE></A>.</P>
|
|
|
|
<H2><A NAME="SIGABRT"><CODE>SIGABRT</CODE></A></H2>
|
|
|
|
<P><CODE>
|
|
#define <B>SIGABRT</B> <I><integer constant expression >= 0></I>
|
|
</CODE></P>
|
|
|
|
<P>The macro yields the <CODE>sig</CODE> argument value
|
|
for the abort signal.</P>
|
|
|
|
<H2><A NAME="SIGFPE"><CODE>SIGFPE</CODE></A></H2>
|
|
|
|
<P><CODE>
|
|
#define <B>SIGFPE</B> <I><integer constant expression >= 0></I>
|
|
</CODE></P>
|
|
|
|
<P>The macro yields the <CODE>sig</CODE> argument value for the arithmetic
|
|
error signal, such as for division by zero or result out of range.</P>
|
|
|
|
<H2><A NAME="SIGILL"><CODE>SIGILL</CODE></A></H2>
|
|
|
|
<P><CODE>
|
|
#define <B>SIGILL</B> <I><integer constant expression >= 0></I>
|
|
</CODE></P>
|
|
|
|
<P>The macro yields the <CODE>sig</CODE> argument value for the invalid
|
|
execution signal, such as for a corrupted function image.</P>
|
|
|
|
<H2><A NAME="SIGINT"><CODE>SIGINT</CODE></A></H2>
|
|
|
|
<P><CODE>
|
|
#define <B>SIGINT</B> <I><integer constant expression >= 0></I>
|
|
</CODE></P>
|
|
|
|
<P>The macro yields the <CODE>sig</CODE> argument value for the asynchronous
|
|
interactive attention signal.</P>
|
|
|
|
<H2><A NAME="SIGSEGV"><CODE>SIGSEGV</CODE></A></H2>
|
|
|
|
<P><CODE>
|
|
#define <B>SIGSEGV</B> <I><integer constant expression >= 0></I>
|
|
</CODE></P>
|
|
|
|
<P>The macro yields the <CODE>sig</CODE> argument value for the invalid
|
|
storage access signal, such as for an erroneous
|
|
<A HREF="express.html#lvalue expression" tppabs="http://ccs.ucsd.edu/c/express.html#lvalue expression">lvalue expression</A>.</P>
|
|
|
|
<H2><A NAME="SIGTERM"><CODE>SIGTERM</CODE></A></H2>
|
|
|
|
<P><CODE>
|
|
#define <B>SIGTERM</B> <I><integer constant expression >= 0></I>
|
|
</CODE></P>
|
|
|
|
<P>The macro yields the <CODE>sig</CODE> argument value for the asynchronous
|
|
termination request signal.</P>
|
|
|
|
<H2><A NAME="SIG_DFL"><CODE>SIG_DFL</CODE></A></H2>
|
|
|
|
<P><CODE>
|
|
#define <B>SIG_DFL</B> <I><address constant expression></I>
|
|
</CODE></P>
|
|
|
|
<P>The macro yields the <CODE>func</CODE> argument value to
|
|
<A HREF="#signal"><CODE>signal</CODE></A>
|
|
to specify default signal handling.</P>
|
|
|
|
<H2><A NAME="SIG_ERR"><CODE>SIG_ERR</CODE></A></H2>
|
|
|
|
<P><CODE>
|
|
#define <B>SIG_ERR</B> <I><address constant expression></I>
|
|
</CODE></P>
|
|
|
|
<P>The macro yields the
|
|
<A HREF="#signal"><CODE>signal</CODE></A>
|
|
return value to specify an erroneous call.</P>
|
|
|
|
<H2><A NAME="SIG_IGN"><CODE>SIG_IGN</CODE></A></H2>
|
|
|
|
<P><CODE>
|
|
#define <B>SIG_IGN</B> <I><address constant expression></I>
|
|
</CODE></P>
|
|
|
|
<P>The macro yields the <CODE>func</CODE> argument value to
|
|
<A HREF="#signal"><CODE>signal</CODE></A>
|
|
to specify that the target environment is to henceforth ignore the
|
|
signal.</P>
|
|
|
|
<H2><A NAME="raise"><CODE>raise</CODE></A></H2>
|
|
|
|
<P><CODE>
|
|
int <B>raise</B>(int sig);
|
|
</CODE></P>
|
|
|
|
<P>The function sends the signal <CODE>sig</CODE> and returns
|
|
zero if the signal is successfully reported.</P>
|
|
|
|
<H2><A NAME="sig_atomic_t"><CODE>sig_atomic_t</CODE></A></H2>
|
|
|
|
<P><CODE>
|
|
typedef <I>i-type</I> <B>sig_atomic_t</B>;
|
|
</CODE></P>
|
|
|
|
<P>The type is the integer type <CODE><I>i-type</I></CODE> for objects whose
|
|
stored value is altered by an assigning operator as an
|
|
<B><A NAME="atomic operation">atomic operation</A></B>
|
|
(an operation that never has its execution suspended
|
|
while partially completed).
|
|
You declare such objects to communicate between
|
|
<A HREF="#signal handler">signal handlers</A>
|
|
and the rest of the program.</P>
|
|
|
|
<H2><A NAME="signal"><CODE>signal</CODE></A></H2>
|
|
|
|
<P><CODE>
|
|
void (*<B>signal</B>(int sig, void (*func)(int)))(int);
|
|
</CODE></P>
|
|
|
|
<P>The function specifies the new handling for signal <CODE>sig</CODE>
|
|
and returns the previous handling, if successful; otherwise, it returns
|
|
<A HREF="#SIG_ERR"><CODE>SIG_ERR</CODE></A>.</P>
|
|
|
|
<UL>
|
|
<LI>If <CODE>func</CODE> is
|
|
<A HREF="#SIG_DFL"><CODE>SIG_DFL</CODE></A>,
|
|
the target environment commences
|
|
default handling (as defined by the implementation).
|
|
|
|
<LI>If <CODE>func</CODE> is
|
|
<A HREF="#SIG_IGN"><CODE>SIG_IGN</CODE></A>,
|
|
the target environment ignores subsequent reporting of the signal.
|
|
|
|
<LI>Otherwise, <CODE>func</CODE> must be the address of a function returning
|
|
<I>void</I> that the target environment calls with a single <I>int</I>
|
|
argument. The target environment calls this function to handle the
|
|
signal when it is next reported,
|
|
with the value of the signal as its argument.
|
|
</UL>
|
|
|
|
<P>When the target environment calls a signal handler:</P>
|
|
|
|
<UL>
|
|
<LI>The target environment can block further occurrences of the
|
|
corresponding signal until the handler returns, calls
|
|
<A HREF="setjmp.html#longjmp" tppabs="http://ccs.ucsd.edu/c/setjmp.html#longjmp"><CODE>longjmp</CODE></A>,
|
|
or calls <CODE>signal</CODE> for that signal.
|
|
|
|
<LI>The target environment can perform default handling of further
|
|
occurrences of the corresponding signal.
|
|
|
|
<LI>For signal
|
|
<A HREF="#SIGILL"><CODE>SIGILL</CODE></A>,
|
|
the target environment can leave handling unchanged for that signal.
|
|
</UL>
|
|
|
|
<HR>
|
|
<P>See also the
|
|
<B><A HREF="index.html#Table of Contents" tppabs="http://ccs.ucsd.edu/c/index.html#Table of Contents">Table of Contents</A></B> and the
|
|
<B><A HREF="_index.html" tppabs="http://ccs.ucsd.edu/c/_index.html">Index</A></B>.</P>
|
|
|
|
<P><I>
|
|
<A HREF="crit_pb.html" tppabs="http://ccs.ucsd.edu/c/crit_pb.html">Copyright</A> © 1989-1996
|
|
by P.J. Plauger and Jim Brodie. All rights reserved.</I></P>
|
|
|
|
</BODY></HTML>
|