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

📄 sleep.html

📁 IEEE 1003.1-2003, Single Unix Specification v3
💻 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>sleep</title></head><body bgcolor="white"><script type="text/javascript" language="JavaScript" src="../jscript/codes.js"></script><basefont size="3"> <a name="sleep"></a> <a name="tag_03_705"></a><!-- sleep --> <!--header start--><center><font size="2">The Open Group Base Specifications Issue 6<br>IEEE Std 1003.1, 2003 Edition<br>Copyright &copy; 2001-2003 The IEEE and The Open Group, All Rights reserved.</font></center><!--header end--><hr size="2" noshade><h4><a name="tag_03_705_01"></a>NAME</h4><blockquote>sleep - suspend execution for an interval of time</blockquote><h4><a name="tag_03_705_02"></a>SYNOPSIS</h4><blockquote class="synopsis"><p><code><tt>#include &lt;<a href="../basedefs/unistd.h.html">unistd.h</a>&gt;<br><br> unsigned sleep(unsigned</tt> <i>seconds</i><tt>);<br></tt></code></p></blockquote><h4><a name="tag_03_705_03"></a>DESCRIPTION</h4><blockquote><p>The <i>sleep</i>() function shall cause the calling thread to be suspended from execution until either the number of realtimeseconds specified by the argument <i>seconds</i> has elapsed or a signal is delivered to the calling thread and its action is toinvoke a signal-catching function or to terminate the process. The suspension time may be longer than requested due to thescheduling of other activity by the system.</p><p>If a SIGALRM signal is generated for the calling process during execution of <i>sleep</i>() and if the SIGALRM signal is beingignored or blocked from delivery, it is unspecified whether <i>sleep</i>() returns when the SIGALRM signal is scheduled. If thesignal is being blocked, it is also unspecified whether it remains pending after <i>sleep</i>() returns or it is discarded.</p><p>If a SIGALRM signal is generated for the calling process during execution of <i>sleep</i>(), except as a result of a prior callto <a href="../functions/alarm.html"><i>alarm</i>()</a>, and if the SIGALRM signal is not being ignored or blocked from delivery,it is unspecified whether that signal has any effect other than causing <i>sleep</i>() to return.</p><p>If a signal-catching function interrupts <i>sleep</i>() and examines or changes either the time a SIGALRM is scheduled to begenerated, the action associated with the SIGALRM signal, or whether the SIGALRM signal is blocked from delivery, the results areunspecified.</p><p>If a signal-catching function interrupts <i>sleep</i>() and calls <a href="../functions/siglongjmp.html"><i>siglongjmp</i>()</a>or <a href="../functions/longjmp.html"><i>longjmp</i>()</a> to restore an environment saved prior to the <i>sleep</i>() call, theaction associated with the SIGALRM signal and the time at which a SIGALRM signal is scheduled to be generated are unspecified. Itis also unspecified whether the SIGALRM signal is blocked, unless the process' signal mask is restored as part of theenvironment.</p><p><sup>[<a href="javascript:open_code('XSI')">XSI</a>]</sup> <img src="../images/opt-start.gif" alt="[Option Start]" border="0">Interactions between <i>sleep</i>() and any of <a href="../functions/setitimer.html"><i>setitimer</i>()</a>, <a href="../functions/ualarm.html"><i>ualarm</i>()</a>, or <a href="../functions/usleep.html"><i>usleep</i>()</a> are unspecified. <imgsrc="../images/opt-end.gif" alt="[Option End]" border="0"></p></blockquote><h4><a name="tag_03_705_04"></a>RETURN VALUE</h4><blockquote><p>If <i>sleep</i>() returns because the requested time has elapsed, the value returned shall be 0. If <i>sleep</i>() returns dueto delivery of a signal, the return value shall be the &quot;unslept&quot; amount (the requested time minus the time actually slept) inseconds.</p></blockquote><h4><a name="tag_03_705_05"></a>ERRORS</h4><blockquote><p>No errors are defined.</p></blockquote><hr><div class="box"><em>The following sections are informative.</em></div><h4><a name="tag_03_705_06"></a>EXAMPLES</h4><blockquote><p>None.</p></blockquote><h4><a name="tag_03_705_07"></a>APPLICATION USAGE</h4><blockquote><p>None.</p></blockquote><h4><a name="tag_03_705_08"></a>RATIONALE</h4><blockquote><p>There are two general approaches to the implementation of the <i>sleep</i>() function. One is to use the <a href="../functions/alarm.html"><i>alarm</i>()</a> function to schedule a SIGALRM signal and then suspend the process waiting for thatsignal. The other is to implement an independent facility. This volume of IEEE&nbsp;Std&nbsp;1003.1-2001 permits eitherapproach.</p><p>In order to comply with the requirement that no primitive shall change a process attribute unless explicitly described by thisvolume of IEEE&nbsp;Std&nbsp;1003.1-2001, an implementation using SIGALRM must carefully take into account any SIGALRM signalscheduled by previous <a href="../functions/alarm.html"><i>alarm</i>()</a> calls, the action previously established for SIGALRM,and whether SIGALRM was blocked. If a SIGALRM has been scheduled before the <i>sleep</i>() would ordinarily complete, the<i>sleep</i>() must be shortened to that time and a SIGALRM generated (possibly simulated by direct invocation of thesignal-catching function) before <i>sleep</i>() returns. If a SIGALRM has been scheduled after the <i>sleep</i>() would ordinarilycomplete, it must be rescheduled for the same time before <i>sleep</i>() returns. The action and blocking for SIGALRM must be savedand restored.</p><p>Historical implementations often implement the SIGALRM-based version using <a href="../functions/alarm.html"><i>alarm</i>()</a>and <a href="../functions/pause.html"><i>pause</i>()</a>. One such implementation is prone to infinite hangups, as described in <ahref="pause.html"><i>pause</i>()</a> . Another such implementation uses the C-language <a href="../functions/setjmp.html"><i>setjmp</i>()</a> and <a href="../functions/longjmp.html"><i>longjmp</i>()</a> functions to avoid thatwindow. That implementation introduces a different problem: when the SIGALRM signal interrupts a signal-catching function installedby the user to catch a different signal, the <a href="../functions/longjmp.html"><i>longjmp</i>()</a> aborts that signal-catchingfunction. An implementation based on <a href="../functions/sigprocmask.html"><i>sigprocmask</i>()</a>, <a href="../functions/alarm.html"><i>alarm</i>()</a>, and <a href="../functions/sigsuspend.html"><i>sigsuspend</i>()</a> can avoid theseproblems.</p><p>Despite all reasonable care, there are several very subtle, but detectable and unavoidable, differences between the two types ofimplementations. These are the cases mentioned in this volume of IEEE&nbsp;Std&nbsp;1003.1-2001 where some other activity relatingto SIGALRM takes place, and the results are stated to be unspecified. All of these cases are sufficiently unusual as not to be ofconcern to most applications.</p><p>See also the discussion of the term <i>realtime</i> in <a href="alarm.html"><i>alarm</i>()</a> .</p><p>Since <i>sleep</i>() can be implemented using <a href="../functions/alarm.html"><i>alarm</i>()</a>, the discussion about alarmsoccurring early under <a href="../functions/alarm.html"><i>alarm</i>()</a> applies to <i>sleep</i>() as well.</p><p>Application writers should note that the type of the argument <i>seconds</i> and the return value of <i>sleep</i>() is<b>unsigned</b>. That means that a Strictly Conforming POSIX System Interfaces Application cannot pass a value greater than theminimum guaranteed value for {UINT_MAX}, which the ISO&nbsp;C standard sets as 65535, and any application passing a larger value isrestricting its portability. A different type was considered, but historical implementations, including those with a 16-bit<b>int</b> type, consistently use either <b>unsigned</b> or <b>int</b>.</p><p>Scheduling delays may cause the process to return from the <i>sleep</i>() function significantly after the requested time. Insuch cases, the return value should be set to zero, since the formula (requested time minus the time actually spent) yields anegative number and <i>sleep</i>() returns an <b>unsigned</b>.</p></blockquote><h4><a name="tag_03_705_09"></a>FUTURE DIRECTIONS</h4><blockquote><p>None.</p></blockquote><h4><a name="tag_03_705_10"></a>SEE ALSO</h4><blockquote><p><a href="alarm.html"><i>alarm</i>()</a> , <a href="getitimer.html"><i>getitimer</i>()</a> , <a href="nanosleep.html"><i>nanosleep</i>()</a> , <a href="pause.html"><i>pause</i>()</a> , <a href="sigaction.html"><i>sigaction</i>()</a>, <a href="sigsetjmp.html"><i>sigsetjmp</i>()</a> , <a href="ualarm.html"><i>ualarm</i>()</a> , <a href="usleep.html"><i>usleep</i>()</a> , the Base Definitions volume of IEEE&nbsp;Std&nbsp;1003.1-2001, <a href="../basedefs/unistd.h.html"><i>&lt;unistd.h&gt;</i></a></p></blockquote><h4><a name="tag_03_705_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_705_12"></a>Issue 5</h4><blockquote><p>The DESCRIPTION is updated for alignment with the POSIX Threads Extension.</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>

⌨️ 快捷键说明

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