1 .\" Hey Emacs! This file is -*- nroff -*- source.
3 .\" Copyright (C) Markus Kuhn, 1996
5 .\" This is free documentation; you can redistribute it and/or
6 .\" modify it under the terms of the GNU General Public License as
7 .\" published by the Free Software Foundation; either version 2 of
8 .\" the License, or (at your option) any later version.
10 .\" The GNU General Public License's references to "object code"
11 .\" and "executables" are to be interpreted as the output of any
12 .\" document formatting or typesetting system, including
13 .\" intermediate and printed output.
15 .\" This manual is distributed in the hope that it will be useful,
16 .\" but WITHOUT ANY WARRANTY; without even the implied warranty of
17 .\" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 .\" GNU General Public License for more details.
20 .\" You should have received a copy of the GNU General Public
21 .\" License along with this manual; if not, write to the Free
22 .\" Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111,
25 .\" 1996-04-10 Markus Kuhn <mskuhn@cip.informatik.uni-erlangen.de>
26 .\" First version written
27 .\" Modified, 2004-10-24, aeb
28 .TH NANOSLEEP 2 2007-07-26 "Linux" "Linux Programmer's Manual"
30 nanosleep \- pause execution for a specified time
34 .BI "int nanosleep(const struct timespec *" req ", struct timespec *" rem );
37 Feature Test Macro Requirements for glibc (see
38 .BR feature_test_macros (7)):
42 _POSIX_C_SOURCE\ >=\ 199309L
45 delays the execution of the program for at least the time specified in
47 The function can return earlier if a signal has been delivered to the
49 In this case, it returns \-1, sets \fIerrno\fP to
52 remaining time into the structure pointed to by
59 can then be used to call
61 again and complete the specified pause.
65 is used to specify intervals of time with nanosecond precision.
74 time_t tv_sec; /* seconds */
75 long tv_nsec; /* nanoseconds */
80 The value of the nanoseconds field must be in the range 0 to 999999999.
87 has the advantage of not affecting any signals, it is standardized by
88 POSIX, it provides higher timing resolution, and it allows to continue
89 a sleep that has been interrupted by a signal more easily.
91 On successfully sleeping for the requested interval,
94 If the call is interrupted by a signal handler or encounters an error,
95 then it returns \-1, with
97 set to indicate the error.
101 Problem with copying information from user space.
104 The pause has been interrupted by a non-blocked signal that was
105 delivered to the process.
106 The remaining sleep time has been written
107 into *\fIrem\fP so that the process can easily call
109 again and continue with the pause.
114 field was not in the range 0 to 999999999 or
120 The current implementation of
122 is based on the normal kernel timer mechanism, which has a resolution
123 of 1/\fIHZ\fP\ s (see
127 pauses always for at least the specified time, however it can take up
128 to 10 ms longer than specified until the process becomes runnable
130 For the same reason, the value returned in case of a delivered
131 signal in *\fIrem\fP is usually rounded to the next larger multiple of
134 In order to support applications requiring much more precise pauses
135 (e.g., in order to control some time-critical hardware),
137 would handle pauses of up to 2\ ms by busy waiting with microsecond
138 precision when called from a process scheduled under a real-time policy
143 This special extension was removed in kernel 2.5.39,
144 hence is still present in
145 current 2.4 kernels, but not in 2.6 kernels.
149 is stopped by a signal (e.g.,
151 then the call fails with the error
153 after the process is resumed by a
156 If the system call is subsequently restarted,
157 then the time that the process spent in the stopped state is
158 \fInot\fP counted against the sleep interval.
160 .BR sched_setscheduler (2),
162 .BR timer_create (3),