Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

3 lat temu
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  2. <html>
  3. <!-- Created by GNU Texinfo 6.5, http://www.gnu.org/software/texinfo/ -->
  4. <head>
  5. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  6. <title>signal (The Red Hat newlib C Library)</title>
  7. <meta name="description" content="signal (The Red Hat newlib C Library)">
  8. <meta name="keywords" content="signal (The Red Hat newlib C Library)">
  9. <meta name="resource-type" content="document">
  10. <meta name="distribution" content="global">
  11. <meta name="Generator" content="makeinfo">
  12. <link href="index.html#Top" rel="start" title="Top">
  13. <link href="Document-Index.html#Document-Index" rel="index" title="Document Index">
  14. <link href="Document-Index.html#SEC_Contents" rel="contents" title="Table of Contents">
  15. <link href="Signals.html#Signals" rel="up" title="Signals">
  16. <link href="Timefns.html#Timefns" rel="next" title="Timefns">
  17. <link href="raise.html#raise" rel="prev" title="raise">
  18. <style type="text/css">
  19. <!--
  20. a.summary-letter {text-decoration: none}
  21. blockquote.indentedblock {margin-right: 0em}
  22. blockquote.smallindentedblock {margin-right: 0em; font-size: smaller}
  23. blockquote.smallquotation {font-size: smaller}
  24. div.display {margin-left: 3.2em}
  25. div.example {margin-left: 3.2em}
  26. div.lisp {margin-left: 3.2em}
  27. div.smalldisplay {margin-left: 3.2em}
  28. div.smallexample {margin-left: 3.2em}
  29. div.smalllisp {margin-left: 3.2em}
  30. kbd {font-style: oblique}
  31. pre.display {font-family: inherit}
  32. pre.format {font-family: inherit}
  33. pre.menu-comment {font-family: serif}
  34. pre.menu-preformatted {font-family: serif}
  35. pre.smalldisplay {font-family: inherit; font-size: smaller}
  36. pre.smallexample {font-size: smaller}
  37. pre.smallformat {font-family: inherit; font-size: smaller}
  38. pre.smalllisp {font-size: smaller}
  39. span.nolinebreak {white-space: nowrap}
  40. span.roman {font-family: initial; font-weight: normal}
  41. span.sansserif {font-family: sans-serif; font-weight: normal}
  42. ul.no-bullet {list-style: none}
  43. -->
  44. </style>
  45. </head>
  46. <body lang="en">
  47. <a name="signal"></a>
  48. <div class="header">
  49. <p>
  50. Previous: <a href="raise.html#raise" accesskey="p" rel="prev">raise</a>, Up: <a href="Signals.html#Signals" accesskey="u" rel="up">Signals</a> &nbsp; [<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>
  51. </div>
  52. <hr>
  53. <a name="signal_002d_002d_002dspecify-handler-subroutine-for-a-signal"></a>
  54. <h3 class="section">7.3 <code>signal</code>&mdash;specify handler subroutine for a signal</h3>
  55. <a name="index-signal"></a>
  56. <a name="index-_005fsignal_005fr"></a>
  57. <p><strong>Synopsis</strong>
  58. </p><div class="example">
  59. <pre class="example">#include &lt;signal.h&gt;
  60. void (*signal(int <var>sig</var>, void(*<var>func</var>)(int))) (int);
  61. void (*_signal_r(void *<var>reent</var>, int <var>sig</var>, void(*<var>func</var>)(int))) (int);
  62. </pre></div>
  63. <p><strong>Description</strong><br>
  64. <code>signal</code> provides a simple signal-handling implementation for embedded
  65. targets.
  66. </p>
  67. <p><code>signal</code> allows you to request changed treatment for a particular
  68. signal <var>sig</var>. You can use one of the predefined macros <code>SIG_DFL</code>
  69. (select system default handling) or <code>SIG_IGN</code> (ignore this signal)
  70. as the value of <var>func</var>; otherwise, <var>func</var> is a function pointer
  71. that identifies a subroutine in your program as the handler for this signal.
  72. </p>
  73. <p>Some of the execution environment for signal handlers is
  74. unpredictable; notably, the only library function required to work
  75. correctly from within a signal handler is <code>signal</code> itself, and
  76. only when used to redefine the handler for the current signal value.
  77. </p>
  78. <p>Static storage is likewise unreliable for signal handlers, with one
  79. exception: if you declare a static storage location as &lsquo;<code>volatile
  80. sig_atomic_t</code>&rsquo;, then you may use that location in a signal handler to
  81. store signal values.
  82. </p>
  83. <p>If your signal handler terminates using <code>return</code> (or implicit
  84. return), your program&rsquo;s execution continues at the point
  85. where it was when the signal was raised (whether by your program
  86. itself, or by an external event). Signal handlers can also
  87. use functions such as <code>exit</code> and <code>abort</code> to avoid returning.
  88. </p>
  89. <p>The alternate function <code>_signal_r</code> is the reentrant version.
  90. The extra argument <var>reent</var> is a pointer to a reentrancy structure.
  91. </p>
  92. <br>
  93. <p><strong>Returns</strong><br>
  94. If your request for a signal handler cannot be honored, the result is
  95. <code>SIG_ERR</code>; a specific error number is also recorded in <code>errno</code>.
  96. </p>
  97. <p>Otherwise, the result is the previous handler (a function pointer or
  98. one of the predefined macros).
  99. </p>
  100. <br>
  101. <p><strong>Portability</strong><br>
  102. ANSI C requires <code>signal</code>.
  103. </p>
  104. <p>No supporting OS subroutines are required to link with <code>signal</code>, but
  105. it will not have any useful effects, except for software generated signals,
  106. without an operating system that can actually raise exceptions.
  107. </p>
  108. <br>
  109. <hr>
  110. <div class="header">
  111. <p>
  112. Previous: <a href="raise.html#raise" accesskey="p" rel="prev">raise</a>, Up: <a href="Signals.html#Signals" accesskey="u" rel="up">Signals</a> &nbsp; [<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>
  113. </div>
  114. </body>
  115. </html>