linux延时函数
来源:互联网 发布:禾川plc编程软件下载 编辑:程序博客网 时间:2024/04/30 11:13
很好的总结,很实用
linux延时函数(转载)
应用层:
#include <unistd.h>
1、unsigned int sleep(unsigned int seconds); 秒级
2、int usleep(useconds_t usec); 微秒级:1/10^-6
补:
以前对于Linux下的延时函数只用过Sleep,不过最近发现还有其他的函数:
延时可以采用如下函数:
unsigned int sleep(unsigned int seconds);
sleep()会使目前程式陷入「
冬眠
」seconds秒,除非收到「
不可抵
」的信号。
如果sleep()没睡饱,它将会返回还需要补眠的时间,否则一般返回零。
void usleep(unsigned long usec);
usleep与sleep()类同,不同之处在於秒的单位为10E-6秒。
int select(0,NULL,NULL,NULL,struct timeval *tv);
可以利用select的实作sleep()的功能,它将不会等待任何事件发生。
int nanosleep(struct timespec *req,struct timespec *rem);
nanosleep会沉睡req所指定的时间,若rem为non-null,而且没睡饱,将会把要补眠的时间放在rem上。
#include
3、int nanosleep(const struct timespec *req, struct timespec *rem);
struct timespec {
time_t tv_sec; /* seconds */
long tv_nsec; /* nanoseconds */
};
// The value of the nanoseconds field must be in the range 0 to 999999999.
#include
#include
void Sleep(int iSec,int iUsec)
{
struct timeval tv;
tv.tv_sec=iSec;
tv.tv_usec=iUsec;
select(0,NULL,NULL,NULL,&tv);
}
iSec 为延时秒数,Usec为延时微秒数.
注:1秒=1000毫秒=1000000微秒=1000000000纳秒=1000000000000皮秒=1000000000000000飞秒
1s=1000ms=1000000us=1000000000ns=1000000000000ps=1000000000000000fs
内核层:
include <linux/delay.h>
1、void ndelay(unsigned long nsecs); 纳秒级:1/10^-10
2、void udelay(unsigned long usecs); 微秒级: 1/10^-6
3、void mdelay(unsigned long msecs); 毫秒级:1/10^-3
本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/skywalker_ll/archive/2009/12/02/4922414.aspx
- Linux中的延时函数
- linux延时函数
- linux延时函数
- linux延时函数
- Linux中的延时函数
- LINUX系统延时函数
- linux延时函数
- Linux中的延时函数 .
- Linux延时函数
- Linux中的延时函数
- Linux 内核延时函数
- Linux中的延时函数
- Linux中的延时函数
- linux延时函数
- linux延时函数
- linux 延时函数
- linux延时函数
- Linux中的延时函数
- PCI设备配置空间问题
- Paxos算法
- 透过HAL(硬件抽象层)看顶层API是如何访问硬件
- Android中G-Sensor相关流程
- 哈尔滨工业大学—仪器科学与技术考研专业课
- linux延时函数
- Dell(D630)外置麦克风卡拉OK设置
- ch4_drill
- PHP 中 header()函数的作用
- 我的第一个应用宣告失败.
- Need more time to read? Get rid of your TV.没时间读书?远离电视!
- 加入图片
- 对C#事件的理解
- 如何查看编程语言排名