⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sigaction.html

📁 posix标准英文,html格式
💻 HTML
📖 第 1 页 / 共 3 页
字号:
This flag affects the behavior of interruptible functions; that is, those specified to fail with <i>errno</i> set to [EINTR]. Ifset, and a function specified as interruptible is interrupted by this signal, the function shall restart and shall not fail with[EINTR] unless otherwise specified. If the flag is not set, interruptible functions interrupted by this signal shall fail with<i>errno</i> set to [EINTR]. <img src="../images/opt-end.gif" alt="[Option End]" border="0"></dd><dt>SA_SIGINFO</dt><dd>If cleared and the signal is caught, the signal-catching function shall be entered as: <pre><tt>void func(int</tt> <i>signo</i><tt>);</tt></pre><p>where <i>signo</i> is the only argument to the signal-catching function. In this case, the application shall use the<i>sa_handler</i> member to describe the signal-catching function and the application shall not modify the <i>sa_sigaction</i>member.</p><p><sup>[<a href="javascript:open_code('XSI')">XSI|RTS</a>]</sup> <img src="../images/opt-start.gif" alt="[Option Start]" border="0"> If SA_SIGINFO is set and the signal is caught, the signal-catching function shall be entered as:</p><pre><tt>void func(int</tt> <i>signo</i><tt>, siginfo_t *</tt><i>info</i><tt>, void *</tt><i>context</i><tt>);</tt></pre><p>where two additional arguments are passed to the signal-catching function. The second argument shall point to an object of type<b>siginfo_t</b> explaining the reason why the signal was generated; the third argument can be cast to a pointer to an object oftype <b>ucontext_t</b> to refer to the receiving thread's context that was interrupted when the signal was delivered. In this case,the application shall use the <i>sa_sigaction</i> member to describe the signal-catching function and the application shall notmodify the <i>sa_handler</i> member.</p><p>The <i>si_signo</i> member contains the system-generated signal number. <img src="../images/opt-end.gif" alt="[Option End]"border="0"></p><p><sup>[<a href="javascript:open_code('XSI')">XSI</a>]</sup> <img src="../images/opt-start.gif" alt="[Option Start]" border="0">The <i>si_errno</i> member may contain implementation-defined additional error information; if non-zero, it contains an errornumber identifying the condition that caused the signal to be generated. <img src="../images/opt-end.gif" alt="[Option End]"border="0"></p><p><sup>[<a href="javascript:open_code('XSI')">XSI|RTS</a>]</sup> <img src="../images/opt-start.gif" alt="[Option Start]" border="0"> The <i>si_code</i> member contains a code identifying the cause of the signal. <img src="../images/opt-end.gif" alt="[Option End]" border="0"></p><p><sup>[<a href="javascript:open_code('XSI')">XSI</a>]</sup> <img src="../images/opt-start.gif" alt="[Option Start]" border="0">If the value of <i>si_code</i> is less than or equal to 0, then the signal was generated by a process and <i>si_pid</i> and<i>si_uid</i>, respectively, indicate the process ID and the real user ID of the sender. <img src="../images/opt-end.gif" alt="[Option End]" border="0"> The <a href="../basedefs/signal.h.html"><i>&lt;signal.h&gt;</i></a> header description containsinformation about the signal-specific contents of the elements of the <b>siginfo_t</b> type.</p></dd><dt>SA_NOCLDWAIT</dt><dd><sup>[<a href="javascript:open_code('XSI')">XSI</a>]</sup> <img src="../images/opt-start.gif" alt="[Option Start]" border="0">If set, and <i>sig</i> equals SIGCHLD, child processes of the calling processes shall not be transformed into zombie processes whenthey terminate. If the calling process subsequently waits for its children, and the process has no unwaited-for children that weretransformed into zombie processes, it shall block until all of its children terminate, and <a href="../functions/wait.html"><i>wait</i>()</a>, <a href="../functions/waitid.html"><i>waitid</i>()</a>, and <a href="../functions/waitpid.html"><i>waitpid</i>()</a> shall fail and set <i>errno</i> to [ECHILD]. Otherwise, terminating childprocesses shall be transformed into zombie processes, unless SIGCHLD is set to SIG_IGN. <img src="../images/opt-end.gif" alt="[Option End]" border="0"></dd><dt>SA_NODEFER</dt><dd><sup>[<a href="javascript:open_code('XSI')">XSI</a>]</sup> <img src="../images/opt-start.gif" alt="[Option Start]" border="0">If set and <i>sig</i> is caught, <i>sig</i> shall not be added to the thread's signal mask on entry to the signal handler unless itis included in <i>sa_mask</i>. Otherwise, <i>sig</i> shall always be added to the thread's signal mask on entry to the signalhandler. <img src="../images/opt-end.gif" alt="[Option End]" border="0"></dd></dl><p>When a signal is caught by a signal-catching function installed by <i>sigaction</i>(), a new signal mask is calculated andinstalled for the duration of the signal-catching function (or until a call to either <a href="../functions/sigprocmask.html"><i>sigprocmask</i>()</a> or <a href="../functions/sigsuspend.html"><i>sigsuspend</i>()</a> ismade). This mask is formed by taking the union of the current signal mask and the value of the <i>sa_mask</i> for the signal beingdelivered <sup>[<a href="javascript:open_code('XSI')">XSI</a>]</sup> <img src="../images/opt-start.gif" alt="[Option Start]"border="0"> &nbsp;unless SA_NODEFER or SA_RESETHAND is set, <img src="../images/opt-end.gif" alt="[Option End]" border="0"> andthen including the signal being delivered. If and when the user's signal handler returns normally, the original signal mask isrestored.</p><p>Once an action is installed for a specific signal, it shall remain installed until another action is explicitly requested (byanother call to <i>sigaction</i>()), <sup>[<a href="javascript:open_code('XSI')">XSI</a>]</sup> <img src="../images/opt-start.gif"alt="[Option Start]" border="0"> &nbsp;until the SA_RESETHAND flag causes resetting of the handler, <img src="../images/opt-end.gif" alt="[Option End]" border="0"> &nbsp;or until one of the <i><a href="../functions/exec.html">exec</a></i>functions is called.</p><p>If the previous action for <i>sig</i> had been established by <a href="../functions/signal.html"><i>signal</i>()</a>, the valuesof the fields returned in the structure pointed to by <i>oact</i> are unspecified, and in particular <i>oact</i>-&gt;<i>sa_handler</i> is not necessarily the same value passed to <a href="../functions/signal.html"><i>signal</i>()</a>. However, if apointer to the same structure or a copy thereof is passed to a subsequent call to <i>sigaction</i>() via the <i>act</i> argument,handling of the signal shall be as if the original call to <a href="../functions/signal.html"><i>signal</i>()</a> wererepeated.</p><p>If <i>sigaction</i>() fails, no new signal handler is installed.</p><p>It is unspecified whether an attempt to set the action for a signal that cannot be caught or ignored to SIG_DFL is ignored orcauses an error to be returned with <i>errno</i> set to [EINVAL].</p><p>If SA_SIGINFO is not set in <i>sa_flags</i>, then the disposition of subsequent occurrences of <i>sig</i> when it is alreadypending is implementation-defined; the signal-catching function shall be invoked with a single argument. <sup>[<a href="javascript:open_code('RTS')">RTS</a>]</sup> <img src="../images/opt-start.gif" alt="[Option Start]" border="0"> &nbsp;If theimplementation supports the Realtime Signals Extension option, and if SA_SIGINFO is set in <i>sa_flags</i>, then subsequentoccurrences of <i>sig</i> generated by <a href="../functions/sigqueue.html"><i>sigqueue</i>()</a> or as a result of anysignal-generating function that supports the specification of an application-defined value (when <i>sig</i> is already pending)shall be queued in FIFO order until delivered or accepted; the signal-catching function shall be invoked with three arguments. Theapplication specified value is passed to the signal-catching function as the <i>si_value</i> member of the <b>siginfo_t</b>structure. <img src="../images/opt-end.gif" alt="[Option End]" border="0"></p><p>The result of the use of <i>sigaction</i>() and a <a href="../functions/sigwait.html"><i>sigwait</i>()</a> function concurrentlywithin a process on the same signal is unspecified.</p></blockquote><h4><a name="tag_03_680_04"></a>RETURN VALUE</h4><blockquote><p>Upon successful completion, <i>sigaction</i>() shall return 0; otherwise, -1 shall be returned, <i>errno</i> shall be set toindicate the error, and no new signal-catching function shall be installed.</p></blockquote><h4><a name="tag_03_680_05"></a>ERRORS</h4><blockquote><p>The <i>sigaction</i>() function shall fail if:</p><dl compact><dt>[EINVAL]</dt><dd>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 asignal that cannot be ignored.</dd><dt>[ENOTSUP]</dt><dd>The SA_SIGINFO bit flag is set in the <i>sa_flags</i> field of the <b>sigaction</b> structure, and the implementation does notsupport either the Realtime Signals Extension option, or the XSI Extension option.</dd></dl><p>The <i>sigaction</i>() function may fail if:</p><dl compact><dt>[EINVAL]</dt><dd>An attempt was made to set the action to SIG_DFL for a signal that cannot be caught or ignored (or both).</dd></dl></blockquote><hr><div class="box"><em>The following sections are informative.</em></div><h4><a name="tag_03_680_06"></a>EXAMPLES</h4><blockquote><h5><a name="tag_03_680_06_01"></a>Establishing a Signal Handler</h5><p>The following example demonstrates the use of <i>sigaction</i>() to establish a handler for the SIGINT signal.</p><pre><tt>#include &lt;signal.h&gt;<br>static void handler(int signum){    /* Take appropriate actions for signal delivery */}<br>int main(){    struct sigaction sa;<br>    sa.sa_handler = handler;    sigemptyset(&amp;sa.sa_mask);    sa.sa_flags = SA_RESTART; /* Restart functions if                                 interrupted by handler */    if (sigaction(SIGINT, &amp;sa, NULL) == -1)        /* Handle error */;<br>    /* Further code */}</tt></pre></blockquote><h4><a name="tag_03_680_07"></a>APPLICATION USAGE</h4><blockquote><p>The <i>sigaction</i>() function supersedes the <a href="../functions/signal.html"><i>signal</i>()</a> function, and should beused in preference. In particular, <i>sigaction</i>() and <a href="../functions/signal.html"><i>signal</i>()</a> should not be usedin the same process to control the same signal. The behavior of reentrant functions, as defined in the DESCRIPTION, is as specifiedby this volume of IEEE&nbsp;Std&nbsp;1003.1-2001, regardless of invocation from a signal-catching function. This is the onlyintended meaning of the statement that reentrant functions may be used in signal-catching functions without restrictions.Applications must still consider all effects of such functions on such things as data structures, files, and process state. Inparticular, application writers need to consider the restrictions on interactions when interrupting <a href="../functions/sleep.html"><i>sleep</i>()</a> and interactions among multiple handles for a file description. The fact that any

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -