1NANOSLEEP(3P)              POSIX Programmer's Manual             NANOSLEEP(3P)
2
3
4

PROLOG

6       This  manual  page is part of the POSIX Programmer's Manual.  The Linux
7       implementation of this interface may differ (consult the  corresponding
8       Linux  manual page for details of Linux behavior), or the interface may
9       not be implemented on Linux.
10
11

NAME

13       nanosleep — high resolution sleep
14

SYNOPSIS

16       #include <time.h>
17
18       int nanosleep(const struct timespec *rqtp, struct timespec *rmtp);
19

DESCRIPTION

21       The nanosleep() function shall cause the current thread to be suspended
22       from  execution  until  either  the time interval specified by the rqtp
23       argument has elapsed or a signal is delivered to  the  calling  thread,
24       and  its action is to invoke a signal-catching function or to terminate
25       the process. The suspension time may be longer than  requested  because
26       the  argument  value  is rounded up to an integer multiple of the sleep
27       resolution or because of the scheduling of other activity by  the  sys‐
28       tem.  But,  except  for  the case of being interrupted by a signal, the
29       suspension time shall not be less than the time specified by  rqtp,  as
30       measured by the system clock CLOCK_REALTIME.
31
32       The  use  of  the  nanosleep()  function has no effect on the action or
33       blockage of any signal.
34

RETURN VALUE

36       If the nanosleep() function returns  because  the  requested  time  has
37       elapsed, its return value shall be zero.
38
39       If  the nanosleep() function returns because it has been interrupted by
40       a signal, it shall return a value of −1 and set errno to  indicate  the
41       interruption.  If the rmtp argument is non-NULL, the timespec structure
42       referenced by it is updated to contain the amount of time remaining  in
43       the  interval  (the  requested time minus the time actually slept). The
44       rqtp and rmtp arguments may point to the same object. If the rmtp argu‐
45       ment is NULL, the remaining time is not returned.
46
47       If  nanosleep()  fails,  it shall return a value of −1 and set errno to
48       indicate the error.
49

ERRORS

51       The nanosleep() function shall fail if:
52
53       EINTR  The nanosleep() function was interrupted by a signal.
54
55       EINVAL The rqtp argument specified a nanosecond value less than zero or
56              greater than or equal to 1000 million.
57
58       The following sections are informative.
59

EXAMPLES

61       None.
62

APPLICATION USAGE

64       None.
65

RATIONALE

67       It  is common to suspend execution of a thread for an interval in order
68       to poll the status of a non-interrupting function. A  large  number  of
69       actual  needs  can  be met with a simple extension to sleep() that pro‐
70       vides finer resolution.
71
72       In the POSIX.1‐1990 standard and SVR4, it is possible to implement such
73       a  routine, but the frequency of wakeup is limited by the resolution of
74       the alarm() and sleep() functions. In 4.3 BSD, it is possible to  write
75       such  a routine using no static storage and reserving no system facili‐
76       ties. Although it is possible to write a function  with  similar  func‐
77       tionality  to  sleep()  using the remainder of the timer_*() functions,
78       such a function requires the use of signals and the reservation of some
79       signal number. This volume of POSIX.1‐2008 requires that nanosleep() be
80       non-intrusive of the signals function.
81
82       The nanosleep() function shall return a value of 0 on success and −1 on
83       failure  or if interrupted. This latter case is different from sleep().
84       This was done because the remaining time is returned  via  an  argument
85       structure pointer, rmtp, instead of as the return value.
86

FUTURE DIRECTIONS

88       None.
89

SEE ALSO

91       clock_nanosleep(), sleep()
92
93       The Base Definitions volume of POSIX.1‐2008, <time.h>
94
96       Portions  of  this text are reprinted and reproduced in electronic form
97       from IEEE Std 1003.1, 2013 Edition, Standard for Information Technology
98       --  Portable  Operating  System  Interface (POSIX), The Open Group Base
99       Specifications Issue 7, Copyright (C) 2013 by the Institute of Electri‐
100       cal  and  Electronics  Engineers,  Inc  and  The  Open Group.  (This is
101       POSIX.1-2008 with the 2013 Technical Corrigendum  1  applied.)  In  the
102       event of any discrepancy between this version and the original IEEE and
103       The Open Group Standard, the original IEEE and The Open Group  Standard
104       is  the  referee document. The original Standard can be obtained online
105       at http://www.unix.org/online.html .
106
107       Any typographical or formatting errors that appear  in  this  page  are
108       most likely to have been introduced during the conversion of the source
109       files to man page format. To report such errors,  see  https://www.ker
110       nel.org/doc/man-pages/reporting_bugs.html .
111
112
113
114IEEE/The Open Group                  2013                        NANOSLEEP(3P)
Impressum