NANOSLEEP(3)               POSIX Programmer's Manual              NANOSLEEP(3)



PPRROOLLOOGG
       This manual page is part of the POSIX Programmer's Manual.  The OS
       implementation of this interface may differ (consult the corresponding
       OS manual page for details of OS behavior), or the interface may not be
       implemented on OS.

NNAAMMEE
       nanosleep -- high resolution sleep

SSYYNNOOPPSSIISS
       #include <time.h>

       int nanosleep(const struct timespec *_r_q_t_p, struct timespec *_r_m_t_p);

DDEESSCCRRIIPPTTIIOONN
       The _n_a_n_o_s_l_e_e_p() function shall cause the current thread to be suspended
       from execution until either the time interval specified by the _r_q_t_p
       argument has elapsed or a signal is delivered to the calling thread,
       and its action is to invoke a signal-catching function or to terminate
       the process. The suspension time may be longer than requested because
       the argument value is 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 _r_q_t_p, as
       measured by the system clock CLOCK_REALTIME.

       The use of the _n_a_n_o_s_l_e_e_p() function has no effect on the action or
       blockage of any signal.

RREETTUURRNN VVAALLUUEE
       If the _n_a_n_o_s_l_e_e_p() function returns because the requested time has
       elapsed, its return value shall be zero.

       If the _n_a_n_o_s_l_e_e_p() function returns because it has been interrupted by
       a signal, it shall return a value of -1 and set _e_r_r_n_o to indicate the
       interruption. If the _r_m_t_p argument is non-NULL, the ttiimmeessppeecc structure
       referenced by it is updated to contain the amount of time remaining in
       the interval (the requested time minus the time actually slept). The
       _r_q_t_p and _r_m_t_p arguments can point to the same object. If the _r_m_t_p
       argument is NULL, the remaining time is not returned.

       If _n_a_n_o_s_l_e_e_p() fails, it shall return a value of -1 and set _e_r_r_n_o to
       indicate the error.

EERRRROORRSS
       The _n_a_n_o_s_l_e_e_p() function shall fail if:

       EEIINNTTRR  The _n_a_n_o_s_l_e_e_p() function was interrupted by a signal.

       EEIINNVVAALL The _r_q_t_p argument specified a nanosecond value less than zero or
              greater than or equal to 1000 million.

       _T_h_e _f_o_l_l_o_w_i_n_g _s_e_c_t_i_o_n_s _a_r_e _i_n_f_o_r_m_a_t_i_v_e_.

EEXXAAMMPPLLEESS
       None.

AAPPPPLLIICCAATTIIOONN UUSSAAGGEE
       None.

RRAATTIIOONNAALLEE
       It is common to suspend execution of a thread for an interval in order
       to poll the status of a non-interrupting function. A large number of
       actual needs can be met with a simple extension to _s_l_e_e_p() that
       provides finer resolution.

       In the POSIX.1-1990 standard and SVR4, it is possible to implement such
       a routine, but the frequency of wakeup is limited by the resolution of
       the _a_l_a_r_m() and _s_l_e_e_p() functions. In 4.3 BSD, it is possible to write
       such a routine using no static storage and reserving no system
       facilities. Although it is possible to write a function with similar
       functionality to _s_l_e_e_p() using the remainder of the _t_i_m_e_r___*()
       functions, such a function requires the use of signals and the
       reservation of some signal number. This volume of POSIX.1-2017 requires
       that _n_a_n_o_s_l_e_e_p() be non-intrusive of the signals function.

       The _n_a_n_o_s_l_e_e_p() function shall return a value of 0 on success and -1 on
       failure or if interrupted. This latter case is different from _s_l_e_e_p().
       This was done because the remaining time is returned via an argument
       structure pointer, _r_m_t_p, instead of as the return value.

FFUUTTUURREE DDIIRREECCTTIIOONNSS
       None.

SSEEEE AALLSSOO
       _c_l_o_c_k___n_a_n_o_s_l_e_e_p(), _s_l_e_e_p()

       The Base Definitions volume of POSIX.1-2017, <<ttiimmee..hh>>

CCOOPPYYRRIIGGHHTT
       Portions of this text are reprinted and reproduced in electronic form
       from IEEE Std 1003.1-2017, Standard for Information Technology --
       Portable Operating System Interface (POSIX), The Open Group Base
       Specifications Issue 7, 2018 Edition, Copyright (C) 2018 by the
       Institute of Electrical and Electronics Engineers, Inc and The Open
       Group.  In the event of any discrepancy between this version and the
       original IEEE and The Open Group Standard, the original IEEE and The
       Open Group Standard is the referee document. The original Standard can
       be obtained online at http://www.opengroup.org/unix/online.html .

       Any typographical or formatting errors that appear in this page are
       most likely to have been introduced during the conversion of the source
       files to man page format. To report such errors, see
       https://www.kernel.org/doc/man-pages/reporting_bugs.html .



IEEE/The Open Group                  2017                         NANOSLEEP(3)
