Can anyone explain how ntpd
and /etc/localtime
and system clock
interact with each other, in UNIX or more specific in freeBSD?
I'm giving the following long description of the concepts in case I misunderstand some of them so that you can point it out. My real question is down below.
DATE
When we do the "date modify
" in shell, I think it will modify the /etc/localtime
. /etc/localtime
contains both the date and time and timezone info, which is queried by glibc
functions like localtime()
and the timezone can also be manually set by tzset()
.
clocks
From some other material online, there're two clocks in a computer: the hardware clock
and system clock
. The hardware clock is maintained by the battery on the motherboard while system clock is a software concept. The system clock will be set by hardware clock upon system boot. But it can be later adjusted by ntpd
(correct me if I'm wrong).
ntpd
nptd
is a user space process that gets started a few secs after system starts up. It will query some certain ntp servers config'd by the ntp.conf
. It has the feature of slow time drift adjustment in that it won't make dramatic change to the time. (but how about the timezone, will ntpd query the timezone too and gradually change that? that may take too long..) For dramatic time update, there's an ntpupdate()
api.
Question
I found no resource explaining the interaction between them. Each of these concepts seems to have some independent local files to touch and keep. The reason I ask is because I observe that for the process I wrote, which calls localtime
dynamically everytime user ask to display some data, it doesn't reflect the the timezone change updated by date modify
(Neither time nor timezone got changed in the process).