UNIX Power Tools

UNIX Power ToolsSearch this book
Previous: 51.1 We Are Finally Getting to the Bottom of the Bucket Chapter 51
Miscellaneous Useful Programs and Curiosities
Next: 51.3 ASCII Characters: Listing and Getting Values
 

51.2 How UNIX Keeps Time

Like all other operating systems, UNIX has a concept of the time. And virtually all UNIX systems, even the smallest, include a clock with some sort of battery backup built in.

All UNIX systems keep time by counting the number of microseconds since midnight, January 1, 1970, Greenwich Mean Time. This date is commonly called the epoch, and has folk-significance as the begining of the UNIX era. Although the first work on UNIX began in the late '60s, the first versions of UNIX were available (within Bell Laboratories) in the early '70s.

This count gets updated roughly 60 times per second. The exact rate depends on your particular UNIX system and is determined by the constant, HZ, defined in the header file /usr/include/sys/param.h:

#define   HZ   60

This is the time's "resolution," and is often referred to as the clock's "tick." Note that it has nothing to do with your system's CPU clock rate. Time measurements are normally no more precise than your system's clock resolution, although some systems have added facilities for more precise timing.

If your UNIX system belongs to a network, it is important to keep all the clocks on the network "in sync." Strange things happen if you copy a file from one system to another and its date appears to be some time in the future. Many UNIX systems run a time daemon (one of those mysterious helper programs (1.14)), which takes care of this.

UNIX automatically keeps track of daylight savings time, leap years, and other chronological trivia. When the system is installed, you have to tell it your time zone and the style of daylight savings time you want to observe. As UNIX has become an international standard, the number of time zones (and obscure ways of handling daylight savings time) it can handle correctly has proliferated. In a few cases, you still have to handle these things by hand; for example, in Great Britain, the beginning and end of daylight savings time are set annually by Parliament, on advice from the Navy, and thus changes every year. Care for Libyan Standard Time?

UNIX's internal routines compute time in relation to the epoch, but there is no reason for you to worry about it unless you're a C programmer. A library of time routines can convert between this internal representation and more usable representations; see the UNIX manual page for ctime(3).

- ML


Previous: 51.1 We Are Finally Getting to the Bottom of the Bucket UNIX Power ToolsNext: 51.3 ASCII Characters: Listing and Getting Values
51.1 We Are Finally Getting to the Bottom of the Bucket Book Index51.3 ASCII Characters: Listing and Getting Values

The UNIX CD Bookshelf NavigationThe UNIX CD BookshelfUNIX Power ToolsUNIX in a NutshellLearning the vi Editorsed & awkLearning the Korn ShellLearning the UNIX Operating System