-
系统编程中常用的延时函数:
sleep,usleep -
内核编程中常用的延时函数
ndelay、udelay、mdelay -
sleep:
unsigned int sleep(unsigned seconds);
//if sleep(x) return 0,means run ok
//if return y means run x-y seconds,and release y seconds
unsigned int usleep(useconds_t usec);
//if usleep(x) return 0,means run ok
//else return -1
下面写一个测试的c程序,直接交叉编译tftp下进去修改权限755或者777执行就ok
#include <stdio.h>
#include <unistd.h>
int main(void )
{
int i=1000;
while (1)
{
printf("printf start\n");
sleep(1);
printf("1 second sleep\n");
usleep(1000000);
printf("1000000 usecond sleep\n");
}
}
执行完是这样的:
[root@wly]# ./delay_ctl
printf start
1 second sleep
1000000 usecond sleep
printf start
1 second sleep
1000000 usecond sleep
printf start
1 second sleep