CLOCK_MONOTONIC_RAW
reflects the underlying hardware for measuring time.
In the short term this is mostly correct, but hardware isn't perfect, so it can, over long periods, drift and no longer be synchronised with what the rest of the world considers the time to be.
If you know what the time is meant to be elsewhere in the world, then you can adjust your clock to correct it.
Typically your computer will do this with the Network Time Protocol, or NTP,, by asking trusted computers on the internet what the time is.
Actually correcting the time works by using the adjtimex(2) or clock_adjtime(2) system calls.
This can't be done with CLOCK_MONOTONIC_RAW
,
but can be done with CLOCK_MONOTONIC
.
In addition to being correctable,
CLOCK_MONOTONIC
can be used with clock_nanosleep(2).
This will allow you to sleep for at least the period of time specified, though could be interrupted when a signal is delivered, (which could happen with timer_create(2)).
Similar clocks
If it's more important to get the time quickly,
than to get a more precise time,
such as if you're profiling real-time software and want to not slow it down,
then you can use CLOCK_MONOTONIC_COARSE
.
CLOCK_MONOTONIC
can be used to time events,
but works by counting seconds while the computer is running.
This could be a problem if your computer suspends,
since then it would stop counting.
The solution to this is the CLOCK_BOOTTIME
clock,
which will include seconds spent suspended,
so could be used to time external events.
So far everything discussed has been somewhat abstract, divorced from what we commonly understand to be time.
This will be rectified in the next article in the time series, where we will be covering "real time".