获取内核模块中的当前时间(以秒为单位)

编程入门 行业动态 更新时间:2024-10-28 04:15:58
本文介绍了获取内核模块中的当前时间(以秒为单位)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

在内核模块中以秒为单位(自纪元以来)获取当前时间的标准方法是什么?

What is the standard way to get the current time in seconds (since the epoch) in a kernel module?

我见过涉及获取 xtime 的技术,这些技术非常冗长,涉及 while 循环和锁.一定有更好的方法.

I have seen techniques involving getting xtime which are very long-winded and involve while-loops and locks. There must be a better way.

[这不是重复的.我已经浏览了以前关于 SO 的问题.其中许多的答案要么没有指定使用的函数,要么错误地引用了内核中不允许的 time.h]

[This is not a duplicate. I have looked through previous questions on SO. The answers to many of these either don't specify the function used, or incorrectly refer to time.h which is not allowed in the kernel]

推荐答案

你可以使用 getnstimeofday 来解决这个问题.

You can use getnstimeofday for that.

/* 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 .

更多推荐

获取内核模块中的当前时间(以秒为单位)

本文发布于:2023-10-08 13:46:36,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1472810.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:内核   模块   单位   时间

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!