1.\" $OpenBSD: nanosleep.2,v 1.18 2021/07/25 15:47:26 cheloha Exp $ 2.\" $NetBSD: nanosleep.2,v 1.1 1997/04/17 18:12:02 jtc Exp $ 3.\" 4.\" Copyright (c) 1986, 1991, 1993 5.\" The Regents of the University of California. All rights reserved. 6.\" 7.\" Redistribution and use in source and binary forms, with or without 8.\" modification, are permitted provided that the following conditions 9.\" are met: 10.\" 1. Redistributions of source code must retain the above copyright 11.\" notice, this list of conditions and the following disclaimer. 12.\" 2. Redistributions in binary form must reproduce the above copyright 13.\" notice, this list of conditions and the following disclaimer in the 14.\" documentation and/or other materials provided with the distribution. 15.\" 3. Neither the name of the University nor the names of its contributors 16.\" may be used to endorse or promote products derived from this software 17.\" without specific prior written permission. 18.\" 19.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 20.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 23.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 24.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 25.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 26.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 27.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 28.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 29.\" SUCH DAMAGE. 30.\" 31.\" @(#)sleep.3 8.1 (Berkeley) 6/4/93 32.\" 33.Dd $Mdocdate: July 25 2021 $ 34.Dt NANOSLEEP 2 35.Os 36.Sh NAME 37.Nm nanosleep 38.Nd high resolution sleep 39.Sh SYNOPSIS 40.In time.h 41.Ft int 42.Fn nanosleep "const struct timespec *timeout" "struct timespec *remainder" 43.Sh DESCRIPTION 44The 45.Fn nanosleep 46function suspends execution of the calling thread for at least the given 47.Fa timeout . 48Delivery of an unmasked signal terminates this sleep early, 49even if 50.Dv SA_RESTART 51is set with 52.Xr sigaction 2 53for the interrupting signal. 54.Sh RETURN VALUES 55If 56.Fn nanosleep 57sleeps the full 58.Fa timeout 59without interruption it returns 0. 60Unless 61.Fa remainder 62is 63.Dv NULL , 64it is set to zero. 65.Pp 66If 67.Fn nanosleep 68is interrupted by a signal it returns \-1 and the global variable 69.Va errno 70is set to 71.Dv EINTR . 72Unless 73.Fa remainder 74is 75.Dv NULL , 76it is set to the unslept portion of the 77.Fa timeout . 78.Pp 79Otherwise, 80.Fn nanosleep 81returns \-1 and the global variable 82.Va errno 83is set to indicate the error. 84.Sh ERRORS 85.Fn nanosleep 86will fail if: 87.Bl -tag -width Er 88.It Bq Er EINTR 89The call is interrupted by the delivery of a signal. 90.It Bq Er EINVAL 91.Fa timeout 92specifies a nanosecond value less than zero or greater than or equal to 93one billion, 94or a second value less than zero. 95.It Bq Er EFAULT 96.Fa timeout 97points to memory that is not a valid part of the process address space. 98.It Bq Er EFAULT 99.Fa remainder 100is not 101.Dv NULL 102and points to memory that is not a valid part of the process address space. 103.El 104.Sh SEE ALSO 105.Xr sleep 1 , 106.Xr sigaction 2 , 107.Xr sleep 3 108.Sh STANDARDS 109The 110.Fn nanosleep 111function conforms to 112.St -p1003.1-2008 . 113.Sh HISTORY 114The predecessor of this system call, 115.Fn sleep , 116first appeared in 117.At v2 . 118It was removed in 119.At v7 120and replaced with a C library implementation based on 121.Xr alarm 3 122and 123.Xr signal 3 . 124.Pp 125The 126.Fn nanosleep 127function first appeared in 128.St -p1003.1b-93 . 129.Pp 130This implementation of 131.Fn nanosleep 132first appeared in 133.Nx 1.3 134and was ported to 135.Ox 2.1 . 136