]> git.ipfire.org Git - thirdparty/man-pages.git/blob - man3/usleep.3
proc.5: Note kernel version for /proc/PID/smaps VmFlags "wf" flag
[thirdparty/man-pages.git] / man3 / usleep.3
1 .\" Copyright 1993 David Metcalfe (david@prism.demon.co.uk)
2 .\"
3 .\" %%%LICENSE_START(VERBATIM)
4 .\" Permission is granted to make and distribute verbatim copies of this
5 .\" manual provided the copyright notice and this permission notice are
6 .\" preserved on all copies.
7 .\"
8 .\" Permission is granted to copy and distribute modified versions of this
9 .\" manual under the conditions for verbatim copying, provided that the
10 .\" entire resulting derived work is distributed under the terms of a
11 .\" permission notice identical to this one.
12 .\"
13 .\" Since the Linux kernel and libraries are constantly changing, this
14 .\" manual page may be incorrect or out-of-date. The author(s) assume no
15 .\" responsibility for errors or omissions, or for damages resulting from
16 .\" the use of the information contained herein. The author(s) may not
17 .\" have taken the same level of care in the production of this manual,
18 .\" which is licensed free of charge, as they might when working
19 .\" professionally.
20 .\"
21 .\" Formatted or processed versions of this manual, if unaccompanied by
22 .\" the source, must acknowledge the copyright and authors of this work.
23 .\" %%%LICENSE_END
24 .\"
25 .\" References consulted:
26 .\" Linux libc source code
27 .\" Lewine's _POSIX Programmer's Guide_ (O'Reilly & Associates, 1991)
28 .\" 386BSD man pages
29 .\" Modified 1993-07-24 by Rik Faith (faith@cs.unc.edu)
30 .\" Modified 2001-04-01 by aeb
31 .\" Modified 2003-07-23 by aeb
32 .\"
33 .TH USLEEP 3 2017-09-15 "" "Linux Programmer's Manual"
34 .SH NAME
35 usleep \- suspend execution for microsecond intervals
36 .SH SYNOPSIS
37 .nf
38 .B "#include <unistd.h>"
39 .PP
40 .BI "int usleep(useconds_t " usec );
41 .fi
42 .PP
43 .in -4n
44 Feature Test Macro Requirements for glibc (see
45 .BR feature_test_macros (7)):
46 .in
47 .PP
48 .BR usleep ():
49 .ad l
50 .RS 4
51 .PD 0
52 .TP 4
53 Since glibc 2.12:
54 .nf
55 (_XOPEN_SOURCE\ >=\ 500) && ! (_POSIX_C_SOURCE\ >=\ 200809L)
56 || /* Glibc since 2.19: */ _DEFAULT_SOURCE
57 || /* Glibc versions <= 2.19: */ _BSD_SOURCE
58 .TP 4
59 .fi
60 Before glibc 2.12:
61 _BSD_SOURCE || _XOPEN_SOURCE\ >=\ 500
62 .\" || _XOPEN_SOURCE\ &&\ _XOPEN_SOURCE_EXTENDED
63 .PD
64 .RE
65 .ad b
66 .SH DESCRIPTION
67 The
68 .BR usleep ()
69 function suspends execution of the calling thread for
70 (at least) \fIusec\fP microseconds.
71 The sleep may be lengthened slightly
72 by any system activity or by the time spent processing the call or by the
73 granularity of system timers.
74 .SH RETURN VALUE
75 The
76 .BR usleep ()
77 function returns 0 on success.
78 On error, \-1 is returned, with
79 .I errno
80 set to indicate the cause of the error.
81 .SH ERRORS
82 .TP
83 .B EINTR
84 Interrupted by a signal; see
85 .BR signal (7).
86 .TP
87 .B EINVAL
88 \fIusec\fP is greater than or equal to 1000000.
89 (On systems where that is considered an error.)
90 .SH ATTRIBUTES
91 For an explanation of the terms used in this section, see
92 .BR attributes (7).
93 .TS
94 allbox;
95 lb lb lb
96 l l l.
97 Interface Attribute Value
98 T{
99 .BR usleep ()
100 T} Thread safety MT-Safe
101 .TE
102 .SH CONFORMING TO
103 4.3BSD, POSIX.1-2001.
104 POSIX.1-2001 declares this function obsolete; use
105 .BR nanosleep (2)
106 instead.
107 POSIX.1-2008 removes the specification of
108 .BR usleep ().
109 .PP
110 On the original BSD implementation,
111 and in glibc before version 2.2.2, the return type of this function is
112 .IR void .
113 The POSIX version returns
114 .IR int ,
115 and this is also the prototype used since glibc 2.2.2.
116 .PP
117 Only the
118 .B EINVAL
119 error return is documented by SUSv2 and POSIX.1-2001.
120 .SH NOTES
121 The type
122 .I useconds_t
123 is an unsigned integer type capable of holding integers
124 in the range [0,1000000].
125 Programs will be more portable
126 if they never mention this type explicitly.
127 Use
128 .PP
129 .in +4n
130 .EX
131 #include <unistd.h>
132 \&...
133 unsigned int usecs;
134 \&...
135 usleep(usecs);
136 .EE
137 .in
138 .PP
139 The interaction of this function with the
140 .B SIGALRM
141 signal, and with other timer functions such as
142 .BR alarm (2),
143 .BR sleep (3),
144 .BR nanosleep (2),
145 .BR setitimer (2),
146 .BR timer_create (2),
147 .BR timer_delete (2),
148 .BR timer_getoverrun (2),
149 .BR timer_gettime (2),
150 .BR timer_settime (2),
151 .BR ualarm (3)
152 is unspecified.
153 .SH SEE ALSO
154 .BR alarm (2),
155 .BR getitimer (2),
156 .BR nanosleep (2),
157 .BR select (2),
158 .BR setitimer (2),
159 .BR sleep (3),
160 .BR ualarm (3),
161 .BR time (7)