Linux – Getting the Correct Time

Jul 22
05:08

2008

Richard N Williams

Richard N Williams

  • Share this article on Facebook
  • Share this article on Twitter
  • Share this article on Linkedin

This article explores how Linux systems keep time and how o achieve better time-keeping accuaracy

mediaimage
Normal 0 false false false EN-GB X-NONE X-NONE /* Style Definitions */ table.MsoNormalTable {mso-style-name:"Table Normal"; mso-tstyle-rowband-size:0; mso-tstyle-colband-size:0; mso-style-noshow:yes; mso-style-priority:99; mso-style-qformat:yes; mso-style-parent:""; mso-padding-alt:0cm 5.4pt 0cm 5.4pt; mso-para-margin-top:0cm; mso-para-margin-right:0cm; mso-para-margin-bottom:10.0pt; mso-para-margin-left:0cm; line-height:115%; mso-pagination:widow-orphan; font-size:11.0pt; font-family:"Calibri","sans-serif"; mso-ascii-font-family:Calibri; mso-ascii-theme-font:minor-latin; mso-fareast-font-family:"Times New Roman"; mso-fareast-theme-font:minor-fareast; mso-hansi-font-family:Calibri; mso-hansi-theme-font:minor-latin;}

Ensuring a computer is not only displaying the correct time but that it is being maintained accurately is not as straight-forward as it first sounds.

Most Linux systems have two clocks. The hardware clock,Linux – Getting the Correct Time Articles also known as the CMOS of Bios clock, is usually a simple crystal oscillator with battery back-up that maintains time when your system is off or boots up. This clock is usually located on the motherboard and will run all the time, however these clock chips tend to lose time as the computer ages and the battery weakens.

The other clock, the system clock, is a software clock and it starts when you boot up your system often getting an initial time from the hardware clock. System clocks keep time by adding seconds on to a prime epoch, a base time that for Linux and Unix, began at midnight on January 1, 1970.

However, the hardware clock is a cheap electronic oscillator and cannot maintain time to any useful degree of accuracy. They often drift several seconds a day which for day-to-day process is probably adequate but with time sensitive applications it can cause serious problems.

A better way is to set the system clock using the time from a NTP (Network Time Protocol) time server. These dedicated time servers get a UTC (Coordinated Universal Time) time from an atomic clock which are the most accurate time keepers in the world, not losing a second in time in several millions of years.

Dedicated NTP servers use either a radio receiver to pick-up a radio time and frequency broadcast which are transmitted by several national laboratories or by using the timing signal broadcast from the GPS network.

Linux uses a NTP service called NTP Daemon (ntpd). This uses NTP to adjust the system clock for any drift in time as it frequently check the UTC time source.

To configure the NTP daemon the ntp.conf file in the /etc directory can be used. From here more than one time server can be used as a reference and also the frequency it is checked can also be altered.