📄 nanosleep.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>nanosleep</title></head><body bgcolor="white"><script type="text/javascript" language="JavaScript" src="../jscript/codes.js"></script><basefont size="3"> <a name="nanosleep"></a> <a name="tag_03_402"></a><!-- nanosleep --> <!--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_402_01"></a>NAME</h4><blockquote>nanosleep - high resolution sleep (<b>REALTIME</b>)</blockquote><h4><a name="tag_03_402_02"></a>SYNOPSIS</h4><blockquote class="synopsis"><div class="box"><code><tt><sup>[<a href="javascript:open_code('TMR')">TMR</a>]</sup> <img src="../images/opt-start.gif" alt="[Option Start]" border="0"> #include <<a href="../basedefs/time.h.html">time.h</a>><br><br> int nanosleep(const struct timespec *</tt><i>rqtp</i><tt>, struct timespec *</tt><i>rmtp</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_402_03"></a>DESCRIPTION</h4><blockquote><p>The <i>nanosleep</i>() function shall cause the current thread to be suspended from execution until either the time intervalspecified by the <i>rqtp</i> argument has elapsed or a signal is delivered to the calling thread, and its action is to invoke asignal-catching function or to terminate the process. The suspension time may be longer than requested because the argument valueis rounded up to an integer multiple of the sleep resolution or because of the scheduling of other activity by the system. But,except for the case of being interrupted by a signal, the suspension time shall not be less than the time specified by <i>rqtp</i>,as measured by the system clock CLOCK_REALTIME.</p><p>The use of the <i>nanosleep</i>() function has no effect on the action or blockage of any signal.</p></blockquote><h4><a name="tag_03_402_04"></a>RETURN VALUE</h4><blockquote><p>If the <i>nanosleep</i>() function returns because the requested time has elapsed, its return value shall be zero.</p><p>If the <i>nanosleep</i>() function returns because it has been interrupted by a signal, it shall return a value of -1 and set<i>errno</i> to indicate the interruption. If the <i>rmtp</i> argument is non-NULL, the <b>timespec</b> structure referenced by itis updated to contain the amount of time remaining in the interval (the requested time minus the time actually slept). If the<i>rmtp</i> argument is NULL, the remaining time is not returned.</p><p>If <i>nanosleep</i>() fails, it shall return a value of -1 and set <i>errno</i> to indicate the error.</p></blockquote><h4><a name="tag_03_402_05"></a>ERRORS</h4><blockquote><p>The <i>nanosleep</i>() function shall fail if:</p><dl compact><dt>[EINTR]</dt><dd>The <i>nanosleep</i>() function was interrupted by a signal.</dd><dt>[EINVAL]</dt><dd>The <i>rqtp</i> argument specified a nanosecond value less than zero or greater than or equal to 1000 million.</dd></dl></blockquote><hr><div class="box"><em>The following sections are informative.</em></div><h4><a name="tag_03_402_06"></a>EXAMPLES</h4><blockquote><p>None.</p></blockquote><h4><a name="tag_03_402_07"></a>APPLICATION USAGE</h4><blockquote><p>None.</p></blockquote><h4><a name="tag_03_402_08"></a>RATIONALE</h4><blockquote><p>It is common to suspend execution of a process for an interval in order to poll the status of a non-interrupting function. Alarge number of actual needs can be met with a simple extension to <a href="../functions/sleep.html"><i>sleep</i>()</a> thatprovides finer resolution.</p><p>In the POSIX.1-1990 standard and SVR4, it is possible to implement such a routine, but the frequency of wakeup is limited by theresolution of the <a href="../functions/alarm.html"><i>alarm</i>()</a> and <a href="../functions/sleep.html"><i>sleep</i>()</a>functions. In 4.3 BSD, it is possible to write such a routine using no static storage and reserving no system facilities. Althoughit is possible to write a function with similar functionality to <a href="../functions/sleep.html"><i>sleep</i>()</a> using theremainder of the <a href="../functions/timer_create.html"><i>timer_*</i>()</a> functions, such a function requires the use of signalsand the reservation of some signal number. This volume of IEEE Std 1003.1-2001 requires that <i>nanosleep</i>() benon-intrusive of the signals function.</p><p>The <i>nanosleep</i>() function shall return a value of 0 on success and -1 on failure or if interrupted. This latter case isdifferent from <a href="../functions/sleep.html"><i>sleep</i>()</a>. This was done because the remaining time is returned via anargument structure pointer, <i>rmtp</i>, instead of as the return value.</p></blockquote><h4><a name="tag_03_402_09"></a>FUTURE DIRECTIONS</h4><blockquote><p>None.</p></blockquote><h4><a name="tag_03_402_10"></a>SEE ALSO</h4><blockquote><p><a href="sleep.html"><i>sleep</i>()</a> , the Base Definitions volume of IEEE Std 1003.1-2001, <a href="../basedefs/time.h.html"><i><time.h></i></a></p></blockquote><h4><a name="tag_03_402_11"></a>CHANGE HISTORY</h4><blockquote><p>First released in Issue 5. Included for alignment with the POSIX Realtime Extension.</p></blockquote><h4><a name="tag_03_402_12"></a>Issue 6</h4><blockquote><p>The <i>nanosleep</i>() function is marked as part of the Timers option.</p><p>The [ENOSYS] error condition has been removed as stubs need not be provided if an implementation does not support the Timersoption.</p><p>IEEE Std 1003.1-2001/Cor 1-2002, item XSH/TC1/D6/37 is applied, updating the SEE ALSO section to include the <a href="../functions/clock_nanosleep.html"><i>clock_nanosleep</i>()</a> function.</p></blockquote><div class="box"><em>End of informative text.</em></div><hr><hr size="2" noshade><center><font size="2"><!--footer start-->UNIX ® is a registered Trademark of The Open Group.<br>POSIX ® 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 + -