OSDN Git Service

0808cfd2667d7d08fac857d98c887732366d99dc
[linuxjm/LDP_man-pages.git] / original / 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  2013-12-10 "" "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 .sp
40 .BI "int usleep(useconds_t " usec );
41 .fi
42 .sp
43 .in -4n
44 Feature Test Macro Requirements for glibc (see
45 .BR feature_test_macros (7)):
46 .in
47 .sp
48 .BR usleep ():
49 .ad l
50 .RS 4
51 .PD 0
52 .TP 4
53 Since glibc 2.12:
54 .nf
55 _BSD_SOURCE ||
56     (_XOPEN_SOURCE\ >=\ 500 ||
57         _XOPEN_SOURCE\ &&\ _XOPEN_SOURCE_EXTENDED) &&
58     !(_POSIX_C_SOURCE\ >=\ 200809L || _XOPEN_SOURCE\ >=\ 700)
59 .TP 4
60 .fi
61 Before glibc 2.12:
62 _BSD_SOURCE || _XOPEN_SOURCE\ >=\ 500 ||
63 _XOPEN_SOURCE\ &&\ _XOPEN_SOURCE_EXTENDED
64 .PD
65 .RE
66 .ad b
67 .SH DESCRIPTION
68 The
69 .BR usleep ()
70 function suspends execution of the calling thread for
71 (at least) \fIusec\fP microseconds.
72 The sleep may be lengthened slightly
73 by any system activity or by the time spent processing the call or by the
74 granularity of system timers.
75 .SH RETURN VALUE
76 The
77 .BR usleep ()
78 function returns 0 on success.
79 On error, \-1 is returned, with
80 .I errno
81 set to indicate the cause of the error.
82 .SH ERRORS
83 .TP
84 .B EINTR
85 Interrupted by a signal; see
86 .BR signal (7).
87 .TP
88 .B EINVAL
89 \fIusec\fP is not smaller than 1000000.
90 (On systems where that is considered an error.)
91 .SH ATTRIBUTES
92 .SS Multithreading (see pthreads(7))
93 The
94 .BR usleep ()
95 function is thread-safe.
96 .SH CONFORMING TO
97 4.3BSD, POSIX.1-2001.
98 POSIX.1-2001 declares this function obsolete; use
99 .BR nanosleep (2)
100 instead.
101 POSIX.1-2008 removes the specification of
102 .BR usleep ().
103
104 On the original BSD implementation,
105 and in glibc before version 2.2.2, the return type of this function is
106 .IR void .
107 The POSIX version returns
108 .IR int ,
109 and this is also the prototype used since glibc 2.2.2.
110
111 Only the
112 .B EINVAL
113 error return is documented by SUSv2 and POSIX.1-2001.
114 .SH NOTES
115 The type
116 .I useconds_t
117 is an unsigned integer type capable of holding integers
118 in the range [0,1000000].
119 Programs will be more portable
120 if they never mention this type explicitly.
121 Use
122 .in +4n
123 .nf
124 .sp
125 #include <unistd.h>
126 \&...
127     unsigned int usecs;
128 \&...
129     usleep(usecs);
130 .fi
131 .in
132 .LP
133 The interaction of this function with the
134 .B SIGALRM
135 signal, and with other timer functions such as
136 .BR alarm (2),
137 .BR sleep (3),
138 .BR nanosleep (2),
139 .BR setitimer (2),
140 .BR timer_create (2),
141 .BR timer_delete (2),
142 .BR timer_getoverrun (2),
143 .BR timer_gettime (2),
144 .BR timer_settime (2),
145 .BR ualarm (3)
146 is unspecified.
147 .SH SEE ALSO
148 .BR alarm (2),
149 .BR getitimer (2),
150 .BR nanosleep (2),
151 .BR select (2),
152 .BR setitimer (2),
153 .BR sleep (3),
154 .BR ualarm (3),
155 .BR time (7)
156 .SH COLOPHON
157 This page is part of release 3.67 of the Linux
158 .I man-pages
159 project.
160 A description of the project,
161 information about reporting bugs,
162 and the latest version of this page,
163 can be found at
164 \%http://www.kernel.org/doc/man\-pages/.