usleep - suspend execution for microsecond intervals - 暂停执行 microsecond 间隔

usleep - suspend execution for microsecond intervals - 暂停执行 microsecond 间隔

1. Synopsis

#include <unistd.h>

int usleep(useconds_t usec);

usleep()
Since glibc 2.12:

_BSD_SOURCE ||
    (_XOPEN_SOURCE >= 500 ||
        _XOPEN_SOURCE && _XOPEN_SOURCE_EXTENDED) &&
    !(_POSIX_C_SOURCE >= 200809L || _XOPEN_SOURCE >= 700)

Before glibc 2.12:

_BSD_SOURCE || _XOPEN_SOURCE >= 500 || _XOPEN_SOURCE && _XOPEN_SOURCE_EXTENDED
synopsis [sɪˈnɒpsɪs]:n. 概要,大纲

2. Description

The usleep() function suspends execution of the calling thread for (at least) usec microseconds. 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.
usleep() 函数将调用线程的执行暂停 (至少) usec 微秒。任何系统活动,处理调用所花费的时间或系统计时器的粒度都可能会稍微延长睡眠时间。

granularity [grænjʊ'lærɪtɪ]:n. 间隔尺寸,粒度

3. Return Value

0 on success, -1 on error.

4. Errors

EINTR
Interrupted by a signal; see signal(7).
被信号打断,参见 signal(7)

EINVAL
usec is not smaller than 1000000. (On systems where that is considered an error.)
usec is not smaller than 1000000. (在系统上这被认为是一个错误。)

5. Notes

The type useconds_t is an unsigned integer type capable of holding integers in the range [0,1000000]. Programs will be more portable if they never mention this type explicitly.
useconds_t 类型是一种无符号整数类型,能够容纳范围 [0,1000000] 中的整数。如果程序从不明确提及此类型,则它们将更具可移植性。

#include <unistd.h>
...
    unsigned int usecs;
...
    usleep(usecs);
发布了509 篇原创文章 · 获赞 1824 · 访问量 110万+

猜你喜欢

转载自blog.csdn.net/chengyq116/article/details/104589366