1USLEEP(3) Linux Programmer's Manual USLEEP(3)
2
3
4
6 usleep - suspend execution for microsecond intervals
7
9 #include <unistd.h>
10
11 int usleep(useconds_t usec);
12
13 Feature Test Macro Requirements for glibc (see feature_test_macros(7)):
14
15 usleep():
16 Since glibc 2.12:
17 (_XOPEN_SOURCE >= 500) && ! (_POSIX_C_SOURCE >= 200809L)
18 || /* Glibc since 2.19: */ _DEFAULT_SOURCE
19 || /* Glibc <= 2.19: */ _BSD_SOURCE
20 Before glibc 2.12:
21 _BSD_SOURCE || _XOPEN_SOURCE >= 500
22
24 The usleep() function suspends execution of the calling thread for (at
25 least) usec microseconds. The sleep may be lengthened slightly by any
26 system activity or by the time spent processing the call or by the
27 granularity of system timers.
28
30 The usleep() function returns 0 on success. On error, -1 is returned,
31 with errno set to indicate the error.
32
34 EINTR Interrupted by a signal; see signal(7).
35
36 EINVAL usec is greater than or equal to 1000000. (On systems where
37 that is considered an error.)
38
40 For an explanation of the terms used in this section, see at‐
41 tributes(7).
42
43 ┌────────────────────────────────────────────┬───────────────┬─────────┐
44 │Interface │ Attribute │ Value │
45 ├────────────────────────────────────────────┼───────────────┼─────────┤
46 │usleep() │ Thread safety │ MT-Safe │
47 └────────────────────────────────────────────┴───────────────┴─────────┘
48
50 4.3BSD, POSIX.1-2001. POSIX.1-2001 declares this function obsolete;
51 use nanosleep(2) instead. POSIX.1-2008 removes the specification of
52 usleep().
53
54 On the original BSD implementation, and in glibc before version 2.2.2,
55 the return type of this function is void. The POSIX version returns
56 int, and this is also the prototype used since glibc 2.2.2.
57
58 Only the EINVAL error return is documented by SUSv2 and POSIX.1-2001.
59
61 The type useconds_t is an unsigned integer type capable of holding in‐
62 tegers in the range [0,1000000]. Programs will be more portable if
63 they never mention this type explicitly. Use
64
65 #include <unistd.h>
66 ...
67 unsigned int usecs;
68 ...
69 usleep(usecs);
70
71 The interaction of this function with the SIGALRM signal, and with
72 other timer functions such as alarm(2), sleep(3), nanosleep(2),
73 setitimer(2), timer_create(2), timer_delete(2), timer_getoverrun(2),
74 timer_gettime(2), timer_settime(2), ualarm(3) is unspecified.
75
77 alarm(2), getitimer(2), nanosleep(2), select(2), setitimer(2),
78 sleep(3), ualarm(3), time(7)
79
81 This page is part of release 5.12 of the Linux man-pages project. A
82 description of the project, information about reporting bugs, and the
83 latest version of this page, can be found at
84 https://www.kernel.org/doc/man-pages/.
85
86
87
88 2021-03-22 USLEEP(3)