📄 signal.html
字号:
<HTML><HEAD><TITLE><signal.h></TITLE></HEAD><BODY><H1><A NAME="<signal.h>"><CODE><signal.h></CODE></A></H1><HR><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 canreport some exceptional behavior within the program, such as divisionby zero. Or a signal can report some asynchronous event outside theprogram, such as someone striking an interactive attention key ona keyboard.</P><P>You can report any signal by calling<A HREF="#raise"><CODE>raise</CODE></A>. Each implementationdefines what signals it generates (if any) and under what circumstancesit generates them. An implementation can define signals other thanthe ones listed here. The standard header<CODE><signal.h></CODE> can defineadditional macros with names beginning with <CODE>SIG</CODE> to specifythe 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 environmentcalls when the corresponding signal occurs.The target environment suspends execution of the programuntil the signal handler returns or calls<A HREF="setjmp.html#longjmp"><CODE>longjmp</CODE></A>. For maximumportability, an asynchronous signal handler should only:</P><UL><LI>make calls (that succeed) to the function<A HREF="#signal"><CODE>signal</CODE></A></LI><LI>assign values to objects of type <I>volatile</I><A HREF="#sig_atomic_t"><CODE>sig_atomic_t</CODE></A></LI><LI>return control to its caller</LI></UL><P>Furthermore, in C++, a signal handler should:</P><UL><LI>have <CODE>extern "C"</CODE> linkage</LI><LI>use only language features common to C and C++</LI></UL><P>If the signal reports an error within the program (and the signalis not asynchronous), the signal handler can terminate by calling<A HREF="stdlib.html#abort"><CODE>abort</CODE></A>,<A HREF="stdlib.html#exit"><CODE>exit</CODE></A>, or<A HREF="setjmp.html#longjmp"><CODE>longjmp</CODE></A>.</P><PRE> /* MACROS */#define <A HREF="#SIGABRT"><B>SIGABRT</B></A> <I><integer constant expression >= 0></I>#define <A HREF="#SIGFPE"><B>SIGFPE</B></A> <I><integer constant expression >= 0></I>#define <A HREF="#SIGILL"><B>SIGILL</B></A> <I><integer constant expression >= 0></I>#define <A HREF="#SIGINT"><B>SIGINT</B></A> <I><integer constant expression >= 0></I>#define <A HREF="#SIGSEGV"><B>SIGSEGV</B></A> <I><integer constant expression >= 0></I>#define <A HREF="#SIGTERM"><B>SIGTERM</B></A> <I><integer constant expression >= 0></I>#define <A HREF="#SIG_DFL"><B>SIG_DFL</B></A> <I><address constant expression></I>#define <A HREF="#SIG_ERR"><B>SIG_ERR</B></A> <I><address constant expression></I>#define <A HREF="#SIG_IGN"><B>SIG_IGN</B></A> <I><address constant expression></I> /* TYPES */typedef <I>i-type</I> <A HREF="#sig_atomic_t"><B>sig_atomic_t</B></A>; /* FUNCTIONS */int <A HREF="#raise"><B>raise</B></A>(int sig);void (*<A HREF="#signal"><B>signal</B></A>(int sig, void (*func)(int)))(int);</PRE><H2><A NAME="raise"><CODE>raise</CODE></A></H2><PRE>int <B>raise</B>(int sig);</PRE><P>The function sends the signal <CODE>sig</CODE> and returnszero if the signal is successfully reported.</P><H2><A NAME="sig_atomic_t"><CODE>sig_atomic_t</CODE></A></H2><PRE>typedef <I>i-type</I> <B>sig_atomic_t</B>;</PRE><P>The type is the integer type <CODE><I>i-type</I></CODE> for objects whosestored 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 suspendedwhile 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="SIGABRT"><CODE>SIGABRT</CODE></A></H2><PRE>#define <B>SIGABRT</B> <I><integer constant expression >= 0></I></PRE><P>The macro yields the <CODE>sig</CODE> argument valuefor the abort signal.</P><H2><A NAME="SIGFPE"><CODE>SIGFPE</CODE></A></H2><PRE>#define <B>SIGFPE</B> <I><integer constant expression >= 0></I></PRE><P>The macro yields the <CODE>sig</CODE> argument value for the arithmeticerror signal, such as for division by zero or result out of range.</P><H2><A NAME="SIGILL"><CODE>SIGILL</CODE></A></H2><PRE>#define <B>SIGILL</B> <I><integer constant expression >= 0></I></PRE><P>The macro yields the <CODE>sig</CODE> argument value for the invalidexecution signal, such as for a corrupted function image.</P><H2><A NAME="SIGINT"><CODE>SIGINT</CODE></A></H2><PRE>#define <B>SIGINT</B> <I><integer constant expression >= 0></I></PRE><P>The macro yields the <CODE>sig</CODE> argument value for the asynchronousinteractive attention signal.</P><H2><A NAME="signal"><CODE>signal</CODE></A></H2><PRE>void (*<B>signal</B>(int sig, void (*func)(int)))(int);</PRE><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 commencesdefault 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 thesignal 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 thecorresponding signal until the handler returns, calls<A HREF="setjmp.html#longjmp"><CODE>longjmp</CODE></A>,or calls <CODE>signal</CODE> for that signal.<LI>The target environment can perform default handling of furtheroccurrences 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><H2><A NAME="SIGSEGV"><CODE>SIGSEGV</CODE></A></H2><PRE>#define <B>SIGSEGV</B> <I><integer constant expression >= 0></I></PRE><P>The macro yields the <CODE>sig</CODE> argument value for the invalidstorage access signal, such as for an erroneous<A HREF="express.html#lvalue expression">lvalue expression</A>.</P><H2><A NAME="SIGTERM"><CODE>SIGTERM</CODE></A></H2><PRE>#define <B>SIGTERM</B> <I><integer constant expression >= 0></I></PRE><P>The macro yields the <CODE>sig</CODE> argument value for the asynchronoustermination request signal.</P><H2><A NAME="SIG_DFL"><CODE>SIG_DFL</CODE></A></H2><PRE>#define <B>SIG_DFL</B> <I><address constant expression></I></PRE><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><PRE>#define <B>SIG_ERR</B> <I><address constant expression></I></PRE><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><PRE>#define <B>SIG_IGN</B> <I><address constant expression></I></PRE><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 thesignal.</P><HR><P>See also the<B><A HREF="index.html#Table of Contents">Table of Contents</A></B> and the<B><A HREF="_index.html">Index</A></B>.</P><P><I><A HREF="crit_pb.html">Copyright</A> © 1989-2002by P.J. Plauger and Jim Brodie. All rights reserved.</I></P><!--V4.01:1125--></BODY></HTML>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -