|
- <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
- <html>
- <!-- Created by GNU Texinfo 6.5, http://www.gnu.org/software/texinfo/ -->
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
- <title>signal (The Red Hat newlib C Library)</title>
-
- <meta name="description" content="signal (The Red Hat newlib C Library)">
- <meta name="keywords" content="signal (The Red Hat newlib C Library)">
- <meta name="resource-type" content="document">
- <meta name="distribution" content="global">
- <meta name="Generator" content="makeinfo">
- <link href="index.html#Top" rel="start" title="Top">
- <link href="Document-Index.html#Document-Index" rel="index" title="Document Index">
- <link href="Document-Index.html#SEC_Contents" rel="contents" title="Table of Contents">
- <link href="Signals.html#Signals" rel="up" title="Signals">
- <link href="Timefns.html#Timefns" rel="next" title="Timefns">
- <link href="raise.html#raise" rel="prev" title="raise">
- <style type="text/css">
- <!--
- a.summary-letter {text-decoration: none}
- blockquote.indentedblock {margin-right: 0em}
- blockquote.smallindentedblock {margin-right: 0em; font-size: smaller}
- blockquote.smallquotation {font-size: smaller}
- div.display {margin-left: 3.2em}
- div.example {margin-left: 3.2em}
- div.lisp {margin-left: 3.2em}
- div.smalldisplay {margin-left: 3.2em}
- div.smallexample {margin-left: 3.2em}
- div.smalllisp {margin-left: 3.2em}
- kbd {font-style: oblique}
- pre.display {font-family: inherit}
- pre.format {font-family: inherit}
- pre.menu-comment {font-family: serif}
- pre.menu-preformatted {font-family: serif}
- pre.smalldisplay {font-family: inherit; font-size: smaller}
- pre.smallexample {font-size: smaller}
- pre.smallformat {font-family: inherit; font-size: smaller}
- pre.smalllisp {font-size: smaller}
- span.nolinebreak {white-space: nowrap}
- span.roman {font-family: initial; font-weight: normal}
- span.sansserif {font-family: sans-serif; font-weight: normal}
- ul.no-bullet {list-style: none}
- -->
- </style>
-
-
- </head>
-
- <body lang="en">
- <a name="signal"></a>
- <div class="header">
- <p>
- Previous: <a href="raise.html#raise" accesskey="p" rel="prev">raise</a>, Up: <a href="Signals.html#Signals" accesskey="u" rel="up">Signals</a> [<a href="Document-Index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Document-Index.html#Document-Index" title="Index" rel="index">Index</a>]</p>
- </div>
- <hr>
- <a name="signal_002d_002d_002dspecify-handler-subroutine-for-a-signal"></a>
- <h3 class="section">7.3 <code>signal</code>—specify handler subroutine for a signal</h3>
- <a name="index-signal"></a>
- <a name="index-_005fsignal_005fr"></a>
- <p><strong>Synopsis</strong>
- </p><div class="example">
- <pre class="example">#include <signal.h>
- void (*signal(int <var>sig</var>, void(*<var>func</var>)(int))) (int);
-
- void (*_signal_r(void *<var>reent</var>, int <var>sig</var>, void(*<var>func</var>)(int))) (int);
-
- </pre></div>
- <p><strong>Description</strong><br>
- <code>signal</code> provides a simple signal-handling implementation for embedded
- targets.
- </p>
- <p><code>signal</code> allows you to request changed treatment for a particular
- signal <var>sig</var>. You can use one of the predefined macros <code>SIG_DFL</code>
- (select system default handling) or <code>SIG_IGN</code> (ignore this signal)
- as the value of <var>func</var>; otherwise, <var>func</var> is a function pointer
- that identifies a subroutine in your program as the handler for this signal.
- </p>
- <p>Some of the execution environment for signal handlers is
- unpredictable; notably, the only library function required to work
- correctly from within a signal handler is <code>signal</code> itself, and
- only when used to redefine the handler for the current signal value.
- </p>
- <p>Static storage is likewise unreliable for signal handlers, with one
- exception: if you declare a static storage location as ‘<code>volatile
- sig_atomic_t</code>’, then you may use that location in a signal handler to
- store signal values.
- </p>
- <p>If your signal handler terminates using <code>return</code> (or implicit
- return), your program’s execution continues at the point
- where it was when the signal was raised (whether by your program
- itself, or by an external event). Signal handlers can also
- use functions such as <code>exit</code> and <code>abort</code> to avoid returning.
- </p>
- <p>The alternate function <code>_signal_r</code> is the reentrant version.
- The extra argument <var>reent</var> is a pointer to a reentrancy structure.
- </p>
-
- <br>
- <p><strong>Returns</strong><br>
- If your request for a signal handler cannot be honored, the result is
- <code>SIG_ERR</code>; a specific error number is also recorded in <code>errno</code>.
- </p>
- <p>Otherwise, the result is the previous handler (a function pointer or
- one of the predefined macros).
- </p>
- <br>
- <p><strong>Portability</strong><br>
- ANSI C requires <code>signal</code>.
- </p>
- <p>No supporting OS subroutines are required to link with <code>signal</code>, but
- it will not have any useful effects, except for software generated signals,
- without an operating system that can actually raise exceptions.
- </p>
- <br>
- <hr>
- <div class="header">
- <p>
- Previous: <a href="raise.html#raise" accesskey="p" rel="prev">raise</a>, Up: <a href="Signals.html#Signals" accesskey="u" rel="up">Signals</a> [<a href="Document-Index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Document-Index.html#Document-Index" title="Index" rel="index">Index</a>]</p>
- </div>
-
-
-
- </body>
- </html>
|