I wrote a class to listen for process events via a PF_NETLINK
socket connection.
The recv()
function is given a message which includes a timestamp representing the number of nanoseconds since the last boot of the kernel.
What is the function to convert such a timestamp to real time?
The only thing I can think of is to use the clock_gettime()
function to read both values and generate an offset. But I want to make sure that there isn't already a library that does that for us.
struct timespec realtime;
struct timespec boottime;
clock_gettime(CLOCK_REALTIME, &realtime);
clock_gettime(CLOCK_BOOTTIME, &boottime);
// the following is pseudo code since timespec is a struct
struct timespec offset = realtime - boottime;
struct timespec event_timestamp = ...; // value from PF_NETLINK event
struct timespec event_realtime = event_timesamp + offset;
This looks ugly and that's why I'm hoping there is a C library function that does all of that for us. Is there? If so, what is it?