linux 用户空间 和 内核空间 延时函数
2011-06-19 15:28
267 查看
用户空间:
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上。
~~~~~~~~~~~~~~~~~~~~~~~~~~
实际上用select是万能的,下面的是一个使用select的例子:
#include <time.h>
#include <sys/time.h>
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>
udelay(int n); 延时n微秒
mdelay(int n); 延时n毫秒
ndelay(int n); 延时n纳秒
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上。
~~~~~~~~~~~~~~~~~~~~~~~~~~
实际上用select是万能的,下面的是一个使用select的例子:
#include <time.h>
#include <sys/time.h>
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>
udelay(int n); 延时n微秒
mdelay(int n); 延时n毫秒
ndelay(int n); 延时n纳秒
相关文章推荐
- linux 用户空间 和 内核空间 延时函数
- linux 用户空间 和 内核空间 延时函数
- linux用户空间和内核空间延时函数
- linux 用户空间 和 内核空间 延时函数
- linux 用户空间 和 内核空间 延时函数
- linux 用户空间和内核空间延时函数
- linux 用户空间 和 内核空间 延时函数
- linux 用户空间 和 内核空间 延时函数
- linux 用户空间 和 内核空间 延时函数
- linux用户空间和内核空间延时函数
- linux用户空间和内核空间延时函数
- linux 用户空间 和 内核空间 延时函数
- linux 用户空间 和 内核空间 延时函数
- linux用户空间和内核空间的延时函数
- linux 用户空间 和 内核空间 延时函数
- linux驱动开发--copy_to_user 、copy_from_user函数实现内核空间数据与用户空间数据的相互访问
- linux用户空间的延时函数分析 (2011-08-16 10:28)
- 在 Linux 下用户空间与内核空间数据交换的方式
- 在 Linux 下用户空间与内核空间数据交换的方式,第 1 部分: 内核启动参数、模块参数与sysfs、sysctl、系统调用和netlink
- linux&nbsp;内核与用户空间通信之n…