Issue
I'm developing a keyboard tracker to track all the keys pressed by the user along with time.
I found many blogs on getnstimeofday(struct timespec*)
but it's deprecated in latest kernel version because of the "year 2038 problem on 32-bit architectures". Its replacement function is ktime_get_real_ts64
but I'm not able to understand it.
Can someone help me to give the basic idea to implement it or if you can share the working code?
Solution
You use it pretty much the same way you'd use getnstimeofday
:
#include <linux/time.h>
#include <linux/timekeeping.h>
//...
struct timespec64 now;
ktime_get_real_ts64(&now);
struct tm tm_now;
time64_to_tm(now.tv_sec, 0, &tm_now);
//tm_now is similar to the userspace tm
Answered By - cafce25 Answer Checked By - Dawn Plyler (WPSolving Volunteer)