Linux – Relationship between hardware clock and system clock

clocklinux

I know that hardware clock is RTC, which is running still, even when PC (or another device with RTC) is off. (in linux we can see this time by typing "hwclock")
The second mentioned time, system time, is the time it is really used by OS, by linux.
I can see it by comamnd "date"

But I still don't know, how is system time assigned after PC start. Is there some offset value set in linux, which is then used, and the calculation of system time is done using the hardware time and this offset?

Or it is working in another way?

Best Answer

Yes there are these two clocks. The RTC (aka CMOS Clock/ Hardware Clock) as you referred, and the System Clock (aka Kernel Clock, Software Clock) whose value is saved in the OS config. This system clock is based on Timer Interrupts.

And as is obvious these two may some fractional offset due to which they will deviate and the OS has multiple strategies to deal with the timer drift. One of the common modern ways to keep both in sync using a Time Server like time.windows.com based on the Network Time protocol.

Related Question