获取当前时间内核模块中秒(Get current time in seconds in kernel

2019-07-04 02:25发布

什么是在数秒内获得当前时间(从epoch)内核模块的标准呢?

我所看到的,涉及越来越xtime的技术,这是很啰嗦,涉及while循环和锁。 肯定有更好的办法。

[这不是重复。 我已经通过前面的问题看着左右。 许多这些问题的答案要么不指定使用的功能,或错误地引用到time.h中未在内核允许]

Answer 1:

您可以使用getnstimeofday了点。

/* getnstimeofday - Returns the time of day in a timespec */
void getnstimeofday(struct timespec *ts)

其中struct timespec是:

struct timespec {
    time_t  tv_sec;     /* seconds */
    long    tv_nsec;    /* nanoseconds */
};

是的,你需要#include <linux/time.h>



文章来源: Get current time in seconds in kernel module