📄 sigtimedwait.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>sigtimedwait</title></head><body bgcolor="white"><script type="text/javascript" language="JavaScript" src="../jscript/codes.js"></script><basefont size="3"> <a name="sigtimedwait"></a> <a name="tag_03_699"></a><!-- sigtimedwait --> <!--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_699_01"></a>NAME</h4><blockquote>sigtimedwait, sigwaitinfo - wait for queued signals (<b>REALTIME</b>)</blockquote><h4><a name="tag_03_699_02"></a>SYNOPSIS</h4><blockquote class="synopsis"><div class="box"><code><tt><sup>[<a href="javascript:open_code('RTS')">RTS</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 sigtimedwait(const sigset_t *restrict</tt> <i>set</i><tt>,<br> siginfo_t *restrict</tt> <i>info</i><tt>,<br> const struct timespec *restrict</tt> <i>timeout</i><tt>);<br> int sigwaitinfo(const sigset_t *restrict</tt> <i>set</i><tt>,<br> siginfo_t *restrict</tt> <i>info</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_699_03"></a>DESCRIPTION</h4><blockquote><p>The <i>sigtimedwait</i>() function shall be equivalent to <i>sigwaitinfo</i>() except that if none of the signals specified by<i>set</i> are pending, <i>sigtimedwait</i>() shall wait for the time interval specified in the <b>timespec</b> structurereferenced by <i>timeout</i>. If the <b>timespec</b> structure pointed to by <i>timeout</i> is zero-valued and if none of thesignals specified by <i>set</i> are pending, then <i>sigtimedwait</i>() shall return immediately with an error. If <i>timeout</i>is the NULL pointer, the behavior is unspecified. <sup>[<a href="javascript:open_code('MON')">MON</a>]</sup> <img src="../images/opt-start.gif" alt="[Option Start]" border="0"> If the Monotonic Clock option is supported, the CLOCK_MONOTONICclock shall be used to measure the time interval specified by the <i>timeout</i> argument. <img src="../images/opt-end.gif" alt="[Option End]" border="0"></p><p>The <i>sigwaitinfo</i>() function selects the pending signal from the set specified by <i>set</i>. Should any of multiplepending signals in the range SIGRTMIN to SIGRTMAX be selected, it shall be the lowest numbered one. The selection order betweenrealtime and non-realtime signals, or between multiple pending non-realtime signals, is unspecified. If no signal in <i>set</i> ispending at the time of the call, the calling thread shall be suspended until one or more signals in <i>set</i> become pending oruntil it is interrupted by an unblocked, caught signal.</p><p>The <i>sigwaitinfo</i>() function shall be equivalent to the <a href="../functions/sigwait.html"><i>sigwait</i>()</a> functionif the <i>info</i> argument is NULL. If the <i>info</i> argument is non-NULL, the <i>sigwaitinfo</i>() function shall be equivalentto <a href="../functions/sigwait.html"><i>sigwait</i>()</a>, except that the selected signal number shall be stored in the<i>si_signo</i> member, and the cause of the signal shall be stored in the <i>si_code</i> member. If any value is queued to theselected signal, the first such queued value shall be dequeued and, if the <i>info</i> argument is non-NULL, the value shall bestored in the <i>si_value</i> member of <i>info</i>. The system resource used to queue the signal shall be released and returned tothe system for other use. If no value is queued, the content of the <i>si_value</i> member is undefined. If no further signals arequeued for the selected signal, the pending indication for that signal shall be reset.</p></blockquote><h4><a name="tag_03_699_04"></a>RETURN VALUE</h4><blockquote><p>Upon successful completion (that is, one of the signals specified by <i>set</i> is pending or is generated) <i>sigwaitinfo</i>()and <i>sigtimedwait</i>() shall return the selected signal number. Otherwise, the function shall return a value of -1 and set<i>errno</i> to indicate the error.</p></blockquote><h4><a name="tag_03_699_05"></a>ERRORS</h4><blockquote><p>The <i>sigtimedwait</i>() function shall fail if:</p><dl compact><dt>[EAGAIN]</dt><dd>No signal specified by <i>set</i> was generated within the specified timeout period.</dd></dl><p>The <i>sigtimedwait</i>() and <i>sigwaitinfo</i>() functions may fail if:</p><dl compact><dt>[EINTR]</dt><dd>The wait was interrupted by an unblocked, caught signal. It shall be documented in system documentation whether this errorcauses these functions to fail.</dd></dl><p>The <i>sigtimedwait</i>() function may also fail if:</p><dl compact><dt>[EINVAL]</dt><dd>The <i>timeout</i> argument specified a <i>tv_nsec</i> value less than zero or greater than or equal to 1000 million.</dd></dl><p>An implementation only checks for this error if no signal is pending in <i>set</i> and it is necessary to wait.</p></blockquote><hr><div class="box"><em>The following sections are informative.</em></div><h4><a name="tag_03_699_06"></a>EXAMPLES</h4><blockquote><p>None.</p></blockquote><h4><a name="tag_03_699_07"></a>APPLICATION USAGE</h4><blockquote><p>The <i>sigtimedwait</i>() function times out and returns an [EAGAIN] error. Application writers should note that this isinconsistent with other functions such as <a href="../functions/pthread_cond_timedwait.html"><i>pthread_cond_timedwait</i>()</a>that return [ETIMEDOUT].</p></blockquote><h4><a name="tag_03_699_08"></a>RATIONALE</h4><blockquote><p>Existing programming practice on realtime systems uses the ability to pause waiting for a selected set of events and handle thefirst event that occurs in-line instead of in a signal-handling function. This allows applications to be written in anevent-directed style similar to a state machine. This style of programming is useful for largescale transaction processing in whichthe overall throughput of an application and the ability to clearly track states are more important than the ability to minimizethe response time of individual event handling.</p><p>It is possible to construct a signal-waiting macro function out of the realtime signal function mechanism defined in this volumeof IEEE Std 1003.1-2001. However, such a macro has to include the definition of a generalized handler for all signals tobe waited on. A significant portion of the overhead of handler processing can be avoided if the signal-waiting function is providedby the kernel. This volume of IEEE Std 1003.1-2001 therefore provides two signal-waiting functions-one that waitsindefinitely and one with a timeout-as part of the overall realtime signal function specification.</p><p>The specification of a function with a timeout allows an application to be written that can be broken out of a wait after a set
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -