1<html lang="en"> 2<head> 3<title>Signals - Untitled</title> 4<meta http-equiv="Content-Type" content="text/html"> 5<meta name="description" content="Untitled"> 6<meta name="generator" content="makeinfo 4.13"> 7<link title="Top" rel="start" href="index.html#Top"> 8<link rel="prev" href="Wchar-strings.html#Wchar-strings" title="Wchar strings"> 9<link rel="next" href="Timefns.html#Timefns" title="Timefns"> 10<link href="http://www.gnu.org/software/texinfo/" rel="generator-home" title="Texinfo Homepage"> 11<meta http-equiv="Content-Style-Type" content="text/css"> 12<style type="text/css"><!-- 13 pre.display { font-family:inherit } 14 pre.format { font-family:inherit } 15 pre.smalldisplay { font-family:inherit; font-size:smaller } 16 pre.smallformat { font-family:inherit; font-size:smaller } 17 pre.smallexample { font-size:smaller } 18 pre.smalllisp { font-size:smaller } 19 span.sc { font-variant:small-caps } 20 span.roman { font-family:serif; font-weight:normal; } 21 span.sansserif { font-family:sans-serif; font-weight:normal; } 22--></style> 23<link rel="stylesheet" type="text/css" href="../cs.css"> 24</head> 25<body> 26<div class="node"> 27<a name="Signals"></a> 28<p> 29Next: <a rel="next" accesskey="n" href="Timefns.html#Timefns">Timefns</a>, 30Previous: <a rel="previous" accesskey="p" href="Wchar-strings.html#Wchar-strings">Wchar strings</a>, 31Up: <a rel="up" accesskey="u" href="index.html#Top">Top</a> 32<hr> 33</div> 34 35<h2 class="chapter">7 Signal Handling (<samp><span class="file">signal.h</span></samp>)</h2> 36 37<p>A <dfn>signal</dfn> is an event that interrupts the normal flow of control 38in your program. Your operating environment normally defines the full 39set of signals available (see <samp><span class="file">sys/signal.h</span></samp>), as well as the 40default means of dealing with them—typically, either printing an 41error message and aborting your program, or ignoring the signal. 42 43 <p>All systems support at least the following signals: 44 <dl> 45<dt><code>SIGABRT</code><dd>Abnormal termination of a program; raised by the <<abort>> function. 46 47 <br><dt><code>SIGFPE</code><dd>A domain error in arithmetic, such as overflow, or division by zero. 48 49 <br><dt><code>SIGILL</code><dd>Attempt to execute as a function data that is not executable. 50 51 <br><dt><code>SIGINT</code><dd>Interrupt; an interactive attention signal. 52 53 <br><dt><code>SIGSEGV</code><dd>An attempt to access a memory location that is not available. 54 55 <br><dt><code>SIGTERM</code><dd>A request that your program end execution. 56</dl> 57 58 <p>Two functions are available for dealing with asynchronous 59signals—one to allow your program to send signals to itself (this is 60called <dfn>raising</dfn> a signal), and one to specify subroutines (called 61<dfn>handlers</dfn> to handle particular signals that you anticipate may 62occur—whether raised by your own program or the operating environment. 63 64 <p>To support these functions, <samp><span class="file">signal.h</span></samp> defines three macros: 65 66 <dl> 67<dt><code>SIG_DFL</code><dd>Used with the <code>signal</code> function in place of a pointer to a 68handler subroutine, to select the operating environment's default 69handling of a signal. 70 71 <br><dt><code>SIG_IGN</code><dd>Used with the <code>signal</code> function in place of a pointer to a 72handler, to ignore a particular signal. 73 74 <br><dt><code>SIG_ERR</code><dd>Returned by the <code>signal</code> function in place of a pointer to a 75handler, to indicate that your request to set up a handler could not 76be honored for some reason. 77</dl> 78 79 <p><samp><span class="file">signal.h</span></samp> also defines an integral type, <code>sig_atomic_t</code>. 80This type is not used in any function declarations; it exists only to 81allow your signal handlers to declare a static storage location where 82they may store a signal value. (Static storage is not otherwise 83reliable from signal handlers.) 84 85<ul class="menu"> 86<li><a accesskey="1" href="psignal.html#psignal">psignal</a>: Print a signal message to standard error 87<li><a accesskey="2" href="raise.html#raise">raise</a>: Send a signal 88<li><a accesskey="3" href="signal.html#signal">signal</a>: Specify handler subroutine for a signal 89</ul> 90 91 </body></html> 92 93