1

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).

  • Try to be more terse and to the point with questions if you want quality answers. Now you are basically asking people to write a book for you about FreeBSD time keeping? – snap Aug 21 '11 at 15:40

1 Answers1

1

I think the following answers the main issue in your question if I understood you correctly:

To change the timezone, replace your /etc/localtime with one of the files in /usr/share/zoneinfo directory tree. Setting the time with date command does not change the timezone and thus does not do anything to the /etc/localtime file.

Note that changing /etc/localtime does not necessarily affect running processes. Reboot if you want to be sure that all daemons see the new time zone.

snap
  • 1,201
  • 9
  • 17
  • just to add some info, the hardware clock gets set to the system clock on halt ([like so](http://linux.die.net/man/8/hwclock)) just as the system clock gets set from the hwclock on boot. Secondly, the hwclock might be either UTC (expected by most unices by default) or local time (expected by Windows). If you mix it up and multiboot you'll have wildly fluctuating clock values ;) – Michael Lowman Aug 21 '11 at 15:42
  • 1
    Yeah, good point. UNIX uses UTC for everything internally and thus the kernel and the `ntpd` do not know nor care about time zones. It is only used for presentation to the user by libc time routines. – snap Aug 21 '11 at 15:45
  • On FreeBSD specifically according to adjkerntz(8): If the file /etc/wall_cmos_clock exists, it means that CMOS clock keeps local time (instead of UTC). – polynomial Aug 21 '11 at 20:05