gzyueqian
18529173453
首页 > 新闻中心 > > 正文

实用技巧:Linux下时间延迟以及延缓操作

更新时间: 2008-06-04 14:45:38来源: 粤嵌教育浏览量:788

  1、在内核中计时的头函数是#include

  2、Hz符号指出每秒钟产生的时钟滴答数,也就是1秒钟产生的时间中断。

  3、#include

  volatile unsigned long jiffies 用这个变量来度量时间的变化。

  4、int time_after(unsigned long a, unsigned long b)

  int time_before(unsigned long a, unsigned long b)

  这些布尔表达式以安全的方式比较jiffies的数值,无需考虑计时器溢出的问题。

  5、jiffies表示的时间和其他表示方法之间的数值转换:

unsigned long timespec_to_jiffies(struct timespec *value);
            void jiffies_to_timespec(unsigned long jiffies, struct timespec *value);
            unsigned long timeval_to_jiffies(struct timeval *value);
            void jiffies_to_timeval(unsigned long jiffies, struct timeval *value);

  (每次总是记不住,这次写到blog上以备后患)其中timespec和timeval是linux系统中时钟时间的结构:

struct timeval {
            time_t tv_sec; /* seconds */
            suseconds_t tv_usec; /* microseconds */
            };
            struct timespec
            {
            long int tv_sec;
            long int tv_nsec;
            };

  使用这个结构的头文件在#include 中,一般常用到的函数是:

int gettimeofday(struct timeval *tv, struct timezone *tz);




 


免费预约试听课