Linux 内核时间结构

来源:互联网 发布:ip与mac地址扫描工具 编辑:程序博客网 时间:2024/05/22 15:43

为了自包含而包含此结构, 内核中使用较少:

struct tm {    /*     * the number of seconds after the minute, normally in the range     * 0 to 59, but can be up to 60 to allow for leap seconds     */    int tm_sec;    /* the number of minutes after the hour, in the range 0 to 59*/    int tm_min;    /* the number of hours past midnight, in the range 0 to 23 */    int tm_hour;    /* the day of the month, in the range 1 to 31 */    int tm_mday;    /* the number of months since January, in the range 0 to 11 */    int tm_mon;    /* the number of years since 1900 */    long tm_year;    /* the number of days since Sunday, in the range 0 to 6 */    int tm_wday;    /* the number of days since January 1, in the range 0 to 365 */    int tm_yday;};

内核常用的时间数据结构:

struct timespec {    __kernel_time_t tv_sec;         /* seconds */    long        tv_nsec;        /* nanoseconds */};struct timeval {    __kernel_time_t     tv_sec;     /* seconds */    __kernel_suseconds_t    tv_usec;    /* microseconds */};struct timezone {    int tz_minuteswest; /* minutes west of Greenwich */    int tz_dsttime; /* type of dst correction */};/* * ktime_t: * * A single 64-bit variable is used to store the hrtimers * internal representation of time values in scalar nanoseconds. The * design plays out best on 64-bit CPUs, where most conversions are * NOPs and most arithmetic ktime_t operations are plain arithmetic * operations. * */union ktime {    s64 tv64;};typedef union ktime ktime_t;

内核中常用的时间的函数API:

这里写代码片