📄 sigaction.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-2003 The Open Group, All Rights Reserved --><title>sigaction</title></head><body bgcolor="white"><script type="text/javascript" language="JavaScript" src="../jscript/codes.js"></script><basefont size="3"> <a name="sigaction"></a> <a name="tag_03_680"></a><!-- sigaction --> <!--header start--><center><font size="2">The Open Group Base Specifications Issue 6<br>IEEE Std 1003.1, 2003 Edition<br>Copyright © 2001-2003 The IEEE and The Open Group, All Rights reserved.</font></center><!--header end--><hr size="2" noshade><h4><a name="tag_03_680_01"></a>NAME</h4><blockquote>sigaction - examine and change a signal action</blockquote><h4><a name="tag_03_680_02"></a>SYNOPSIS</h4><blockquote class="synopsis"><div class="box"><code><tt><sup>[<a href="javascript:open_code('CX')">CX</a>]</sup> <img src="../images/opt-start.gif" alt="[Option Start]" border="0"> #include <<a href="../basedefs/signal.h.html">signal.h</a>><br><br> int sigaction(int</tt> <i>sig</i><tt>, const struct sigaction *restrict</tt> <i>act</i><tt>,<br> struct sigaction *restrict</tt> <i>oact</i><tt>); <img src="../images/opt-end.gif" alt="[Option End]" border="0"></tt></code></div><tt><br></tt></blockquote><h4><a name="tag_03_680_03"></a>DESCRIPTION</h4><blockquote><p>The <i>sigaction</i>() function allows the calling process to examine and/or specify the action to be associated with a specificsignal. The argument <i>sig</i> specifies the signal; acceptable values are defined in <a href="../basedefs/signal.h.html"><i><signal.h></i></a>.</p><p>The structure <b>sigaction</b>, used to describe an action to be taken, is defined in the <a href="../basedefs/signal.h.html"><i><signal.h></i></a> header to include at least the following members:</p><center><table border="1" cellpadding="3" align="center"><tr valign="top"><th align="center"><p class="tent"><b>Member Type</b></p></th><th align="center"><p class="tent"><b>Member Name</b></p></th><th align="center"><p class="tent"><b>Description</b></p></th></tr><tr valign="top"><td align="left"><p class="tent"><b>void(*) (int)</b></p></td><td align="left"><p class="tent"><i>sa_handler</i></p></td><td align="left"><p class="tent">Pointer to a signal-catching function or one of the macros SIG_IGN or SIG_DFL.</p></td></tr><tr valign="top"><td align="left"><p class="tent"><b>sigset_t</b></p></td><td align="left"><p class="tent"><i>sa_mask</i></p></td><td align="left"><p class="tent">Additional set of signals to be blocked during execution of signal-catching function.</p></td></tr><tr valign="top"><td align="left"><p class="tent"><b>int</b></p></td><td align="left"><p class="tent"><i>sa_flags</i></p></td><td align="left"><p class="tent">Special flags to affect behavior of signal.</p></td></tr><tr valign="top"><td align="left"><p class="tent"><b>void(*) (int,</b></p></td><td align="left"><p class="tent"><i> </i></p></td><td align="left"><p class="tent"> </p></td></tr><tr valign="top"><td align="left"><p class="tent"><b> siginfo_t *, void *)</b></p></td><td align="left"><p class="tent"><i>sa_sigaction</i></p></td><td align="left"><p class="tent">Pointer to a signal-catching function.</p></td></tr></table></center><p>The storage occupied by <i>sa_handler</i> and <i>sa_sigaction</i> may overlap, and a conforming application shall not use bothsimultaneously.</p><p>If the argument <i>act</i> is not a null pointer, it points to a structure specifying the action to be associated with thespecified signal. If the argument <i>oact</i> is not a null pointer, the action previously associated with the signal is stored inthe location pointed to by the argument <i>oact</i>. If the argument <i>act</i> is a null pointer, signal handling is unchanged;thus, the call can be used to enquire about the current handling of a given signal. The SIGKILL and SIGSTOP signals shall not beadded to the signal mask using this mechanism; this restriction shall be enforced by the system without causing an error to beindicated.</p><p>If the SA_SIGINFO flag (see below) is cleared in the <i>sa_flags</i> field of the <b>sigaction</b> structure, the<i>sa_handler</i> field identifies the action to be associated with the specified signal. <sup>[<a href="javascript:open_code('XSI')">XSI|RTS</a>]</sup> <img src="../images/opt-start.gif" alt="[Option Start]" border="0"> If theSA_SIGINFO flag is set in the <i>sa_flags</i> field, and the implementation supports the Realtime Signals Extension option or theXSI Extension option, the <i>sa_sigaction</i> field specifies a signal-catching function. <img src="../images/opt-end.gif" alt="[Option End]" border="0"> If the SA_SIGINFO bit is cleared and the <i>sa_handler</i> field specifies a signal-catching function,or if the SA_SIGINFO bit is set, the <i>sa_mask</i> field identifies a set of signals that shall be added to the signal mask of thethread before the signal-catching function is invoked. If the <i>sa_handler</i> field specifies a signal-catching function, the<i>sa_mask</i> field identifies a set of signals that shall be added to the process' signal mask before the signal-catchingfunction is invoked.</p><p>The <i>sa_flags</i> field can be used to modify the behavior of the specified signal.</p><p>The following flags, defined in the <a href="../basedefs/signal.h.html"><i><signal.h></i></a> header, can be set in<i>sa_flags</i>:</p><dl compact><dt>SA_NOCLDSTOP</dt><dd>Do not generate SIGCHLD when children stop <sup>[<a href="javascript:open_code('XSI')">XSI</a>]</sup> <img src="../images/opt-start.gif" alt="[Option Start]" border="0"> or stopped children continue. <img src="../images/opt-end.gif"alt="[Option End]" border="0"> <p>If <i>sig</i> is SIGCHLD and the SA_NOCLDSTOP flag is not set in <i>sa_flags</i>, and the implementation supports the SIGCHLDsignal, then a SIGCHLD signal shall be generated for the calling process whenever any of its child processes stop <sup>[<a href="javascript:open_code('XSI')">XSI</a>]</sup> <img src="../images/opt-start.gif" alt="[Option Start]" border="0"> and aSIGCHLD signal may be generated for the calling process whenever any of its stopped child processes are continued. <img src="../images/opt-end.gif" alt="[Option End]" border="0"> If <i>sig</i> is SIGCHLD and the SA_NOCLDSTOP flag is set in<i>sa_flags</i>, then the implementation shall not generate a SIGCHLD signal in this way.</p></dd><dt>SA_ONSTACK</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 an alternate signal stack has been declared with <a href="../functions/sigaltstack.html"><i>sigaltstack</i>()</a>, thesignal shall be delivered to the calling process on that stack. Otherwise, the signal shall be delivered on the current stack. <imgsrc="../images/opt-end.gif" alt="[Option End]" border="0"></dd><dt>SA_RESETHAND</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, the disposition of the signal shall be reset to SIG_DFL and the SA_SIGINFO flag shall be cleared on entry to the signalhandler. <basefont size="2"> <dl><dt><b>Note:</b></dt><dd>SIGILL and SIGTRAP cannot be automatically reset when delivered; the system silently enforces this restriction.</dd></dl><basefont size="3"> Otherwise, the disposition of the signal shall not be modified on entry to the signal handler. <p>In addition, if this flag is set, <i>sigaction</i>() behaves as if the SA_NODEFER flag were also set. <img src="../images/opt-end.gif" alt="[Option End]" border="0"></p></dd><dt>SA_RESTART</dt><dd><sup>[<a href="javascript:open_code('XSI')">XSI</a>]</sup> <img src="../images/opt-start.gif" alt="[Option Start]" border="0">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 process' 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><signal.h></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 process' 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 process' 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"> unless SA_NODEFER or SA_RESETHAND is set, <img src="../images/opt-end.gif" alt="[Option End]" border="0"> and
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -