当前位置: 技术问答>linux和unix
请教Linux下的sleep()函数。。。
来源: 互联网 发布时间:2015-08-07
本文导语: sleep()函数的原型为: unsigned int sleep(unsigned int seconds); 如果我只是想睡眠几个毫秒的时候,我只能把参数搞成float或者double,尽管可以运行,不过要出警告,很是不爽,不知道有什么好的办法可以睡眠几个毫...
sleep()函数的原型为:
unsigned int sleep(unsigned int seconds);
如果我只是想睡眠几个毫秒的时候,我只能把参数搞成float或者double,尽管可以运行,不过要出警告,很是不爽,不知道有什么好的办法可以睡眠几个毫秒的????
顺便说一句:windows下的Sleep函数参数为毫秒数。
谢谢!!!!
unsigned int sleep(unsigned int seconds);
如果我只是想睡眠几个毫秒的时候,我只能把参数搞成float或者double,尽管可以运行,不过要出警告,很是不爽,不知道有什么好的办法可以睡眠几个毫秒的????
顺便说一句:windows下的Sleep函数参数为毫秒数。
谢谢!!!!
|
#include
int usleep(unsigned int microseconds);
or
setitimer (int which, const struct itimeval *value, struct itimerval *ovalue);
int usleep(unsigned int microseconds);
or
setitimer (int which, const struct itimeval *value, struct itimerval *ovalue);
|
可以试试mdelay()。还有微秒级的udelay()。
|
用usleep()函数,以微秒为单位的:
#include
int usleep(unsigned int microseconds);
#include
int usleep(unsigned int microseconds);
|
还有个厉害的
#include
int nanosleep(const struct timespec *req, struct timespec *rem);
#include
int nanosleep(const struct timespec *req, struct timespec *rem);
|
If your Linux OS adopts kernel 2.6.x, you can use nanosleep or select call to implement your requirement. If 2.4.x, it does not support that precision.
|
usleep()实现 1/1000000秒延时
select()实现 1/1000秒延时
select()实现 1/1000秒延时
|
建议用select,
usleep的时间不是很准
usleep的时间不是很准
|
windows下的虽然是毫秒级sleep,可是没有相应的精度保证
|
用setitimer()可以到微秒级.
|
nanosleep
|
pthread_delay_np
|
nanosleep
您可能感兴趣的文章:
本站(WWW.)旨在分享和传播互联网科技相关的资讯和技术,将尽最大努力为读者提供更好的信息聚合和浏览方式。
本站(WWW.)站内文章除注明原创外,均为转载、整理或搜集自网络。欢迎任何形式的转载,转载请注明出处。
本站(WWW.)站内文章除注明原创外,均为转载、整理或搜集自网络。欢迎任何形式的转载,转载请注明出处。