| 1 |
'\" t |
| 2 |
.\" Copyright 1993, David Metcalfe <[email protected]> |
| 3 |
.\" Copyright, the authors of the Linux man-pages project |
| 4 |
.\" |
| 5 |
.\" SPDX-License-Identifier: Linux-man-pages-copyleft |
| 6 |
.\" |
| 7 |
.TH usleep 3 2026-02-08 "Linux man-pages 6.18" |
| 8 |
.SH NAME |
| 9 |
usleep \- suspend execution for microsecond intervals |
| 10 |
.SH LIBRARY |
| 11 |
Standard C library |
| 12 |
.RI ( libc ,\~ \-lc ) |
| 13 |
.SH SYNOPSIS |
| 14 |
.nf |
| 15 |
.B "#include <unistd.h>" |
| 16 |
.P |
| 17 |
.BI "int usleep(useconds_t " usec ); |
| 18 |
.fi |
| 19 |
.P |
| 20 |
.RS -4 |
| 21 |
Feature Test Macro Requirements for glibc (see |
| 22 |
.BR feature_test_macros (7)): |
| 23 |
.RE |
| 24 |
.P |
| 25 |
.BR usleep (): |
| 26 |
.nf |
| 27 |
Since glibc 2.12: |
| 28 |
(_XOPEN_SOURCE >= 500) && ! (_POSIX_C_SOURCE >= 200809L) |
| 29 |
|| /* glibc >= 2.19: */ _DEFAULT_SOURCE |
| 30 |
|| /* glibc <= 2.19: */ _BSD_SOURCE |
| 31 |
Before glibc 2.12: |
| 32 |
_BSD_SOURCE || _XOPEN_SOURCE >= 500 |
| 33 |
.\" || _XOPEN_SOURCE && _XOPEN_SOURCE_EXTENDED |
| 34 |
.fi |
| 35 |
.SH DESCRIPTION |
| 36 |
The |
| 37 |
.BR usleep () |
| 38 |
function suspends execution of the calling thread for |
| 39 |
(at least) |
| 40 |
.I usec |
| 41 |
microseconds. |
| 42 |
The sleep may be lengthened slightly |
| 43 |
by any system activity or by the time spent processing the call or by the |
| 44 |
granularity of system timers. |
| 45 |
.SH RETURN VALUE |
| 46 |
The |
| 47 |
.BR usleep () |
| 48 |
function returns 0 on success. |
| 49 |
On error, \-1 is returned, with |
| 50 |
.I errno |
| 51 |
set to indicate the error. |
| 52 |
.SH ERRORS |
| 53 |
.TP |
| 54 |
.B EINTR |
| 55 |
Interrupted by a signal; |
| 56 |
see |
| 57 |
.BR signal (7). |
| 58 |
.TP |
| 59 |
.B EINVAL |
| 60 |
.I usec |
| 61 |
is greater than or equal to |
| 62 |
.BR 1000000 . |
| 63 |
(On systems where that is considered an error.) |
| 64 |
.SH ATTRIBUTES |
| 65 |
For an explanation of the terms used in this section, see |
| 66 |
.BR attributes (7). |
| 67 |
.TS |
| 68 |
allbox; |
| 69 |
lbx lb lb |
| 70 |
l l l. |
| 71 |
Interface Attribute Value |
| 72 |
T{ |
| 73 |
.na |
| 74 |
.nh |
| 75 |
.BR usleep () |
| 76 |
T} Thread safety MT-Safe |
| 77 |
.TE |
| 78 |
.SH STANDARDS |
| 79 |
None. |
| 80 |
.SH HISTORY |
| 81 |
4.3BSD, POSIX.1-2001. |
| 82 |
POSIX.1-2001 declares it obsolete, suggesting |
| 83 |
.BR nanosleep (2) |
| 84 |
instead. |
| 85 |
Removed in POSIX.1-2008. |
| 86 |
.P |
| 87 |
On the original BSD implementation, |
| 88 |
and before glibc 2.2.2, the return type of this function is |
| 89 |
.IR void . |
| 90 |
The POSIX version returns |
| 91 |
.IR int , |
| 92 |
and this is also the prototype used since glibc 2.2.2. |
| 93 |
.P |
| 94 |
Only the |
| 95 |
.B EINVAL |
| 96 |
error return is documented by SUSv2 and POSIX.1-2001. |
| 97 |
.SH CAVEATS |
| 98 |
The interaction of this function with the |
| 99 |
.B SIGALRM |
| 100 |
signal, and with other timer functions such as |
| 101 |
.BR alarm (2), |
| 102 |
.BR sleep (3), |
| 103 |
.BR nanosleep (2), |
| 104 |
.BR setitimer (2), |
| 105 |
.BR timer_create (2), |
| 106 |
.BR timer_delete (2), |
| 107 |
.BR timer_getoverrun (2), |
| 108 |
.BR timer_gettime (2), |
| 109 |
.BR timer_settime (2), |
| 110 |
.BR ualarm (3) |
| 111 |
is unspecified. |
| 112 |
.SH SEE ALSO |
| 113 |
.BR alarm (2), |
| 114 |
.BR getitimer (2), |
| 115 |
.BR nanosleep (2), |
| 116 |
.BR select (2), |
| 117 |
.BR setitimer (2), |
| 118 |
.BR sleep (3), |
| 119 |
.BR ualarm (3), |
| 120 |
.BR useconds_t (3type), |
| 121 |
.BR time (7) |