如何获得在Linux内核空间当前小时(一天中的时间) [英] How to get current hour (time of day) in linux kernel space

查看:307
本文介绍了如何获得在Linux内核空间当前小时(一天中的时间)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在写一个内核模块检查,看看是否该时间是两个指定小时,并禁止输入,如果它是。这与我想确保我早睡做。 (我知道我还可以使用任意数量的不同的技术,包括cron的等等,但我想学内核编程...)

I'm writing a kernel module that checks to see if the time is between two specified hours, and disables input if it is. This has to do with me wanting to make sure I go to bed early. (I know I could also use any number of different techniques including cron etc, but I wanted to learn kernel programming...)

作为第一个版本,所以我检查,如果当前的小时的开始和结束,这是通过参数模块设置之间。

As a first version, I therefore check if the current hour is between start and end, which are set via parameters to the module.

所以我的问题是:我如何获得当前的小时?我在标准库没有进入通常的计时功能,因为我在内核空间。我猜,我应该使用此do_gettimeofday(),但只给了我秒和纳秒,我需要时间在当前的日子。

My question is therefore : How do I get the current hour? I have no access to the usual time functions in the standard library because I am in kernel space. I'm guessing that I should be using do_gettimeofday() for this, but that only gives me seconds and nanoseconds, and I need hours in the current day.

感谢。

推荐答案

time_to_tm 功能可以将您的帮助,它返回结构的 TM 。时区变量 sys_tz ,它可以帮助您设置您偏移适当地获取本地时间。

time_to_tm function can be of your help, which returns the structure tm. Timezone available in variable sys_tz, it can help you to set your offset properly to get local time.

这篇关于如何获得在Linux内核空间当前小时(一天中的时间)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆