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; see signal(7).
  • EINVAL โ€” usec is greater than or equal to 1000000. (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 the SIGALRM signal, and with other timer functions such as alarm(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
  • ๐Ÿ’– girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms