新浪博客

linux下C语言延时函数

2011-03-06 18:33阅读:
在linux下延时可以采用如下函数:

1.unsigned int sleep(unsigned int seconds);

sleep()会使当前程序休眠seconds秒。如果sleep()没睡饱,它将会返回还需要补眠的时间,否则一般返回零。

2.void usleep(unsigned long usec);

usleep与sleep()类同,不同之处在于休眠的时间单位为毫秒(10E-6秒)。

3.int select(0,NULL,NULL,NULL,struct timeval *tv);

可以利用select实现sleep()的功能,它将不会等待任何事件发生。

4.int nanosleep(struct timespec *req,struct timespec *rem);

nanosleep会沉睡req所指定的时间,若rem为non-null,而且没睡饱,将会把要补眠的时间放在rem上。

我的更多文章

下载客户端阅读体验更佳

APP专享