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

NAME

12       nanosleep - high resolution sleep (REALTIME)
13

SYNOPSIS

15       #include <time.h>
16
17       int nanosleep(const struct timespec *rqtp, struct timespec *rmtp);
18
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). If the
44       rmtp argument is NULL, the remaining time is not returned.
45
46       If nanosleep() fails, it shall return a value of -1 and  set  errno  to
47       indicate the error.
48

ERRORS

50       The nanosleep() function shall fail if:
51
52       EINTR  The nanosleep() function was interrupted by a signal.
53
54       EINVAL The rqtp argument specified a nanosecond value less than zero or
55              greater than or equal to 1000 million.
56
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 process 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  IEEE Std 1003.1-2001  requires  that
80       nanosleep() be 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       sleep(), the Base Definitions volume of IEEE Std 1003.1-2001, <time.h>
92
94       Portions of this text are reprinted and reproduced in  electronic  form
95       from IEEE Std 1003.1, 2003 Edition, Standard for Information Technology
96       -- Portable Operating System Interface (POSIX),  The  Open  Group  Base
97       Specifications  Issue  6,  Copyright  (C) 2001-2003 by the Institute of
98       Electrical and Electronics Engineers, Inc and The Open  Group.  In  the
99       event of any discrepancy between this version and the original IEEE and
100       The Open Group Standard, the original IEEE and The Open Group  Standard
101       is  the  referee document. The original Standard can be obtained online
102       at http://www.opengroup.org/unix/online.html .
103
104
105
106IEEE/The Open Group                  2003                        NANOSLEEP(3P)
Impressum