Files
oldlinux-files/Ref-docs/POSIX/susv3/functions/signal.html
2024-02-19 00:21:47 -05:00

226 lines
10 KiB
HTML

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta name="generator" content="HTML Tidy, see www.w3.org">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link type="text/css" rel="stylesheet" href="style.css"><!-- Generated by The Open Group's rhtm tool v1.2.1 -->
<!-- Copyright (c) 2001 The Open Group, All Rights Reserved -->
<title>signal</title>
</head>
<body bgcolor="white">
<script type="text/javascript" language="JavaScript" src="../jscript/codes.js">
</script>
<basefont size="3"> <a name="signal"></a> <a name="tag_03_690"></a><!-- signal -->
<!--header start-->
<center><font size="2">The Open Group Base Specifications Issue 6<br>
IEEE Std 1003.1-2001<br>
Copyright &copy; 2001 The IEEE and The Open Group, All Rights reserved.</font></center>
<!--header end-->
<hr size="2" noshade>
<h4><a name="tag_03_690_01"></a>NAME</h4>
<blockquote>signal - signal management</blockquote>
<h4><a name="tag_03_690_02"></a>SYNOPSIS</h4>
<blockquote class="synopsis">
<p><code><tt>#include &lt;<a href="../basedefs/signal.h.html">signal.h</a>&gt;<br>
<br>
void (*signal(int</tt> <i>sig</i><tt>, void (*</tt><i>func</i><tt>)(int)))(int);<br>
</tt></code></p>
</blockquote>
<h4><a name="tag_03_690_03"></a>DESCRIPTION</h4>
<blockquote>
<div class="box"><sup>[<a href="javascript:open_code('CX')">CX</a>]</sup> <img src="../images/opt-start.gif" alt="[Option Start]"
border="0"> The functionality described on this reference page is aligned with the ISO&nbsp;C standard. Any conflict between the
requirements described here and the ISO&nbsp;C standard is unintentional. This volume of IEEE&nbsp;Std&nbsp;1003.1-2001 defers to
the ISO&nbsp;C standard. <img src="../images/opt-end.gif" alt="[Option End]" border="0"></div>
<p><sup>[<a href="javascript:open_code('CX')">CX</a>]</sup> <img src="../images/opt-start.gif" alt="[Option Start]" border="0"> Use
of this function is unspecified in a multi-threaded process. <img src="../images/opt-end.gif" alt="[Option End]" border="0"></p>
<p>The <i>signal</i>() function chooses one of three ways in which receipt of the signal number <i>sig</i> is to be subsequently
handled. If the value of <i>func</i> is SIG_DFL, default handling for that signal shall occur. If the value of <i>func</i> is
SIG_IGN, the signal shall be ignored. Otherwise, the application shall ensure that <i>func</i> points to a function to be called
when that signal occurs. An invocation of such a function because of a signal, or (recursively) of any further functions called by
that invocation (other than functions in the standard library), is called a &quot;signal handler&quot;.</p>
<p>When a signal occurs, and <i>func</i> points to a function, it is implementation-defined whether the equivalent of a:</p>
<pre>
<tt>signal(</tt><i>sig</i><tt>, SIG_DFL);
</tt>
</pre>
<p>is executed or the implementation prevents some implementation-defined set of signals (at least including <i>sig</i>) from
occurring until the current signal handling has completed. (If the value of <i>sig</i> is SIGILL, the implementation may
alternatively define that no action is taken.) Next the equivalent of:</p>
<pre>
<tt>(*func)(sig);
</tt>
</pre>
<p>is executed. If and when the function returns, if the value of <i>sig</i> was SIGFPE, SIGILL, or SIGSEGV or any other
implementation-defined value corresponding to a computational exception, the behavior is undefined. Otherwise, the program shall
resume execution at the point it was interrupted. If the signal occurs as the result of calling the <a href=
"../functions/abort.html"><i>abort</i>()</a>, <a href="../functions/raise.html"><i>raise</i>()</a>, <sup>[<a href=
"javascript:open_code('CX')">CX</a>]</sup> <img src="../images/opt-start.gif" alt="[Option Start]" border="0"> <a href=
"../functions/kill.html"><i>kill</i>()</a>, <a href="../functions/pthread_kill.html"><i>pthread_kill</i>()</a>, or <a href=
"../functions/sigqueue.html"><i>sigqueue</i>()</a> <img src="../images/opt-end.gif" alt="[Option End]" border="0"> function, the
signal handler shall not call the <a href="../functions/raise.html"><i>raise</i>()</a> function.</p>
<p>If the signal occurs other than as the result of calling <a href="../functions/abort.html"><i>abort</i>()</a>, <a href=
"../functions/raise.html"><i>raise</i>()</a>, <sup>[<a href="javascript:open_code('CX')">CX</a>]</sup> <img src=
"../images/opt-start.gif" alt="[Option Start]" border="0"> <a href="../functions/kill.html"><i>kill</i>()</a>, <a href=
"../functions/pthread_kill.html"><i>pthread_kill</i>()</a>, or <a href="../functions/sigqueue.html"><i>sigqueue</i>()</a>, <img
src="../images/opt-end.gif" alt="[Option End]" border="0"> &nbsp;the behavior is undefined if the signal handler refers to any
object with static storage duration other than by assigning a value to an object declared as volatile <b>sig_atomic_t</b>, or if
the signal handler calls any function in the standard library other than one of the functions listed in <a href=
"xsh_chap02_04.html#tag_02_04"><i>Signal Concepts</i></a> . Furthermore, if such a call fails, the value of <i>errno</i> is
unspecified.</p>
<p>At program start-up, the equivalent of:</p>
<pre>
<tt>signal(</tt><i>sig</i><tt>, SIG_IGN);
</tt>
</pre>
<p>is executed for some signals, and the equivalent of:</p>
<pre>
<tt>signal(</tt><i>sig</i><tt>, SIG_DFL);
</tt>
</pre>
<p>is executed for all other signals <sup>[<a href="javascript:open_code('CX')">CX</a>]</sup> <img src="../images/opt-start.gif"
alt="[Option Start]" border="0"> &nbsp;(see <i><a href="../functions/exec.html">exec</a></i>). <img src="../images/opt-end.gif"
alt="[Option End]" border="0"></p>
</blockquote>
<h4><a name="tag_03_690_04"></a>RETURN VALUE</h4>
<blockquote>
<p>If the request can be honored, <i>signal</i>() shall return the value of <i>func</i> for the most recent call to <i>signal</i>()
for the specified signal <i>sig</i>. Otherwise, SIG_ERR shall be returned and a positive value shall be stored in <i>errno</i>.</p>
</blockquote>
<h4><a name="tag_03_690_05"></a>ERRORS</h4>
<blockquote>
<p>The <i>signal</i>() function shall fail if:</p>
<dl compact>
<dt>[EINVAL]</dt>
<dd><sup>[<a href="javascript:open_code('CX')">CX</a>]</sup> <img src="../images/opt-start.gif" alt="[Option Start]" border="0">
The <i>sig</i> argument is not a valid signal number or an attempt is made to catch a signal that cannot be caught or ignore a
signal that cannot be ignored. <img src="../images/opt-end.gif" alt="[Option End]" border="0"></dd>
</dl>
<p>The <i>signal</i>() function may fail if:</p>
<dl compact>
<dt>[EINVAL]</dt>
<dd><sup>[<a href="javascript:open_code('CX')">CX</a>]</sup> <img src="../images/opt-start.gif" alt="[Option Start]" border="0"> An
attempt was made to set the action to SIG_DFL for a signal that cannot be caught or ignored (or both). <img src=
"../images/opt-end.gif" alt="[Option End]" border="0"></dd>
</dl>
</blockquote>
<hr>
<div class="box"><em>The following sections are informative.</em></div>
<h4><a name="tag_03_690_06"></a>EXAMPLES</h4>
<blockquote>
<p>None.</p>
</blockquote>
<h4><a name="tag_03_690_07"></a>APPLICATION USAGE</h4>
<blockquote>
<p>The <a href="../functions/sigaction.html"><i>sigaction</i>()</a> function provides a more comprehensive and reliable mechanism
for controlling signals; new applications should use <a href="../functions/sigaction.html"><i>sigaction</i>()</a> rather than
<i>signal</i>().</p>
</blockquote>
<h4><a name="tag_03_690_08"></a>RATIONALE</h4>
<blockquote>
<p>None.</p>
</blockquote>
<h4><a name="tag_03_690_09"></a>FUTURE DIRECTIONS</h4>
<blockquote>
<p>None.</p>
</blockquote>
<h4><a name="tag_03_690_10"></a>SEE ALSO</h4>
<blockquote>
<p><a href="xsh_chap02_04.html#tag_02_04"><i>Signal Concepts</i></a> , <a href="exec.html"><i><a href=
"../functions/exec.html">exec</a></i>()</a> , <a href="pause.html"><i>pause</i>()</a> , <a href=
"sigaction.html"><i>sigaction</i>()</a> , <a href="sigsuspend.html"><i>sigsuspend</i>()</a> , <a href=
"waitid.html"><i>waitid</i>()</a> , the Base Definitions volume of IEEE&nbsp;Std&nbsp;1003.1-2001, <a href=
"../basedefs/signal.h.html"><i>&lt;signal.h&gt;</i></a></p>
</blockquote>
<h4><a name="tag_03_690_11"></a>CHANGE HISTORY</h4>
<blockquote>
<p>First released in Issue 1. Derived from Issue 1 of the SVID.</p>
</blockquote>
<h4><a name="tag_03_690_12"></a>Issue 5</h4>
<blockquote>
<p>Moved from X/OPEN UNIX extension to BASE.</p>
<p>The DESCRIPTION is updated to indicate that the <a href="../functions/sigpause.html"><i>sigpause</i>()</a> function restores the
process' signal mask to its original state before returning.</p>
<p>The RETURN VALUE section is updated to indicate that the <a href="../functions/sigpause.html"><i>sigpause</i>()</a> function
suspends execution of the process until a signal is received, whereupon it returns -1 and sets <i>errno</i> to [EINTR].</p>
</blockquote>
<h4><a name="tag_03_690_13"></a>Issue 6</h4>
<blockquote>
<p>Extensions beyond the ISO&nbsp;C standard are marked.</p>
<p>The DESCRIPTION is updated to avoid use of the term &quot;must&quot; for application requirements.</p>
<p>The DESCRIPTION is updated for alignment with the ISO/IEC&nbsp;9899:1999 standard.</p>
<p>References to the <i>wait3</i>() function are removed.</p>
<p>The <a href="../functions/sighold.html"><i>sighold</i>()</a>, <a href="../functions/sigignore.html"><i>sigignore</i>()</a>, <a
href="../functions/sigrelse.html"><i>sigrelse</i>()</a>, and <a href="../functions/sigset.html"><i>sigset</i>()</a> functions are
split out onto their own reference page.</p>
</blockquote>
<div class="box"><em>End of informative text.</em></div>
<hr>
<hr size="2" noshade>
<center><font size="2"><!--footer start-->
UNIX &reg; is a registered Trademark of The Open Group.<br>
POSIX &reg; is a registered Trademark of The IEEE.<br>
[ <a href="../mindex.html">Main Index</a> | <a href="../basedefs/contents.html">XBD</a> | <a href=
"../utilities/contents.html">XCU</a> | <a href="../functions/contents.html">XSH</a> | <a href="../xrat/contents.html">XRAT</a>
]</font></center>
<!--footer end-->
<hr size="2" noshade>
</body>
</html>