usleep(3)
๐ค usleep(3) โ it's giving "pause, bestie" โจ
okay so real quick, the manual name is usleep and it lives in the Library Functions Manual section of the Linux man-pages. Let's get into it ๐
๐ธ NAME ๐ธ
usleep โ suspend execution for microsecond intervals
๐ LIBRARY ๐
Standard C library (libc, -lc)
๐ SYNOPSIS ๐
#include <unistd.h>
int usleep(useconds_t usec);
โจ Feature Test Macro Requirements for glibc (see feature_test_macros(7)) โจ
usleep():
- Since glibc 2.12:
(_XOPEN_SOURCE >= 500) && ! (_POSIX_C_SOURCE >= 200809L)
|| /* glibc >= 2.19: */ _DEFAULT_SOURCE
|| /* glibc <= 2.19: */ _BSD_SOURCE
- Before glibc 2.12:
_BSD_SOURCE || _XOPEN_SOURCE >= 500
like yes you have to define the right macros, it's the price of admission ๐ญ
๐ฆ DESCRIPTION ๐ฆ
The usleep() function suspends execution of the calling thread for (at least) usec microseconds. ๐ค
so lowkey "at least" is doing a lot of work there โ the sleep may be lengthened slightly by any system activity, or by the time spent processing the call, or by the granularity of system timers. it's not a precision instrument, bestie, it's a vibe ๐
โญ RETURN VALUE โญ
The usleep() function returns 0 on success. ๐ซถ
On error, -1 is returned, with errno set to indicate the error. no cap.
๐ ERRORS ๐
EINTRโ Interrupted by a signal; seesignal(7).EINVALโ usec is greater than or equal to1000000. (On systems where that is considered an error.)
not every system thinks EINVAL is an error bestie, so don't @ the ones that just let it slide ๐
๐ ATTRIBUTES ๐
For an explanation of the terms used in this section, see attributes(7).
- Interface:
usleep() - Attribute: Thread safety
- Value:
MT-Safe
(yes queen, MT-Safe โ she's thread safe, we love that for her ๐
)
๐ง STANDARDS ๐ง
None.
likeโฆ none. she's simply not standardized. iconic behavior honestly ๐
๐ธ HISTORY ๐ธ
4.3BSD, POSIX.1-2001. POSIX.1-2001 declares it obsolete, suggesting nanosleep(2) instead. Removed in POSIX.1-2008.
so yeah, officially deprecated, she got removed, it's giving "retired but still serving" ๐ญ
On the original BSD implementation, and before glibc 2.2.2, the return type of this function is void. The POSIX version returns int, and this is also the prototype used since glibc 2.2.2.
Only the EINVAL error return is documented by SUSv2 and POSIX.1-2001.
๐ CAVEATS ๐
okay this is the part where we slow down ๐
The interaction of this function with theSIGALRMsignal, and with other timer functions such asalarm(2),sleep(3),nanosleep(2),setitimer(2),timer_create(2),timer_delete(2),timer_getoverrun(2),timer_gettime(2),timer_settime(2),ualarm(3)is unspecified.
unspecified means nobody promised you anything, fr fr. keep your timers apart, bestie ๐
๐ SEE ALSO ๐
alarm(2), getitimer(2), nanosleep(2), select(2), setitimer(2), sleep(3), ualarm(3), useconds_t(3type), time(7)
and that's the whole page, mwah ๐ this one came straight outta Linux man-pages 6.20, dated 2026-02-08, and it's the usleep(3) girlies' official lore. go take a nap (for at least usec microseconds) ๐๐
๐ฆ where this page comes from
- arch rolling: man-pages 6.20-1 ยท BSD-2-Clause AND BSD-3-Clause AND BSD-4.3TAHOE AND BSD-4-Clause-UC AND GPL-1.0-or-later AND GPL-2.0-only AND GPL-2.0-or-later AND GPL-3.0-or-later AND LGPL-3.0-linking-exception AND LGPL-3.0-or-later AND LicenseRef-Public-Domain AND LicenseRef-UltraPermissive AND Linux-man-pages-1-para AND Linux-man-pages-copyleft AND Linux-man-pages-copyleft-2-para AND Linux-man-pages-copyleft-var AND MIT AND Spencer-94
- nixpkgs unstable: man-pages 6.20
- ๐ the page's license: Linux-man-pages-copyleft
- Copyright 1993, David Metcalfe <david@prism.demon.co.uk>
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms