📄 ch51_02.htm
字号:
<HTML><!--Distributed by F --><HEAD><TITLE>[Chapter 51] 51.2 How UNIX Keeps Time</TITLE><METANAME="DC.title"CONTENT="UNIX Power Tools"><METANAME="DC.creator"CONTENT="Jerry Peek, Tim O'Reilly & Mike Loukides"><METANAME="DC.publisher"CONTENT="O'Reilly & Associates, Inc."><METANAME="DC.date"CONTENT="1998-08-04T21:57:16Z"><METANAME="DC.type"CONTENT="Text.Monograph"><METANAME="DC.format"CONTENT="text/html"SCHEME="MIME"><METANAME="DC.source"CONTENT="1-56592-260-3"SCHEME="ISBN"><METANAME="DC.language"CONTENT="en-US"><METANAME="generator"CONTENT="Jade 1.1/O'Reilly DocBook 3.0 to HTML 4.0"><LINKREV="made"HREF="mailto:online-books@oreilly.com"TITLE="Online Books Comments"><LINKREL="up"HREF="ch51_01.htm"TITLE="51. Miscellaneous Useful Programs and Curiosities"><LINKREL="prev"HREF="ch51_01.htm"TITLE="51.1 We Are Finally Getting to the Bottom of the Bucket "><LINKREL="next"HREF="ch51_03.htm"TITLE="51.3 ASCII Characters: Listing and Getting Values "></HEAD><BODYBGCOLOR="#FFFFFF"TEXT="#000000"><DIVCLASS="htmlnav"><H1><IMGSRC="gifs/smbanner.gif"ALT="UNIX Power Tools"USEMAP="#srchmap"BORDER="0"></H1><MAPNAME="srchmap"><AREASHAPE="RECT"COORDS="0,0,466,58"HREF="index.htm"ALT="UNIX Power Tools"><AREASHAPE="RECT"COORDS="467,0,514,18"HREF="jobjects/fsearch.htm"ALT="Search this book"></MAP><TABLEWIDTH="515"BORDER="0"CELLSPACING="0"CELLPADDING="0"><TR><TDALIGN="LEFT"VALIGN="TOP"WIDTH="172"><ACLASS="SECT1"HREF="ch51_01.htm"TITLE="51.1 We Are Finally Getting to the Bottom of the Bucket "><IMGSRC="gifs/txtpreva.gif"SRC="gifs/txtpreva.gif"ALT="Previous: 51.1 We Are Finally Getting to the Bottom of the Bucket "BORDER="0"></A></TD><TDALIGN="CENTER"VALIGN="TOP"WIDTH="171"><B><FONTFACE="ARIEL,HELVETICA,HELV,SANSERIF"SIZE="-1">Chapter 51<BR>Miscellaneous Useful Programs and Curiosities</FONT></B></TD><TDALIGN="RIGHT"VALIGN="TOP"WIDTH="172"><ACLASS="SECT1"HREF="ch51_03.htm"TITLE="51.3 ASCII Characters: Listing and Getting Values "><IMGSRC="gifs/txtnexta.gif"SRC="gifs/txtnexta.gif"ALT="Next: 51.3 ASCII Characters: Listing and Getting Values "BORDER="0"></A></TD></TR></TABLE> <HRALIGN="LEFT"WIDTH="515"TITLE="footer"></DIV><DIVCLASS="SECT1"><H2CLASS="sect1"><ACLASS="title"NAME="UPT-ART-1028">51.2 How UNIX Keeps Time</A></H2><PCLASS="para"><ACLASS="indexterm"NAME="AUTOID-59961"></A><ACLASS="indexterm"NAME="AUTOID-59963"></A>Like all other operating systems, UNIX has a concept of the time.And virtually all UNIX systems, even the smallest, include a clockwith some sort of battery backup built in.</P><PCLASS="para">All UNIX systems keep time by counting the number of microsecondssince midnight, January 1, 1970, Greenwich Mean Time. This date iscommonly called the <EMCLASS="emphasis">epoch</EM>, and has folk-significance as the begining of the UNIXera. Although the first work on UNIX began in the late '60s, the firstversions of UNIX were available (within Bell Laboratories) in the early'70s.</P><PCLASS="para">This count gets updated roughly 60 times per second. The exactrate depends on your particular UNIX system and is determined bythe constant, HZ, defined in the header file<EMCLASS="emphasis">/usr/include/sys/param.h</EM>:</P><PCLASS="para"><BLOCKQUOTECLASS="screen"><PRECLASS="screen">#define HZ 60</PRE></BLOCKQUOTE></P><PCLASS="para"> This is the time's "resolution," and is often referred to as theclock's "tick." Note that it has nothing to do with your system'sCPU clock rate. Time measurements are normally no more precise thanyour system's clock resolution, although some systems have addedfacilities for more precise timing.</P><PCLASS="para"><ACLASS="indexterm"NAME="AUTOID-59974"></A>If your UNIX system belongs to a network, it is important to keepall the clocks on the network "in sync." Strange things happen ifyou copy a file from one system to another and its date appears to besome time in the future. Many UNIX systems run a<EMCLASS="emphasis">time daemon</EM> (one of those mysterious<SPANCLASS="link">helper programs (<ACLASS="linkend"HREF="ch01_14.htm"TITLE="The Kernel and Daemons ">1.14</A>)</SPAN>),which takes care of this.</P><PCLASS="para">UNIX automatically keeps track of daylight savings time, leap years,and other chronological trivia. When the system is installed, youhave to tell it your time zone and the style of daylight savings timeyou want to observe. As UNIX has become an international standard,the number of time zones (and obscure ways of handling daylight savingstime) it can handle correctly has proliferated. In a few cases, youstill have to handle these things by hand; for example, in GreatBritain, the beginning and end of daylight savings time are setannually by Parliament, on advice from the Navy, and thus changesevery year. Care for Libyan Standard Time?</P><PCLASS="para">UNIX's internal routines compute time in relation to the epoch, but thereis no reason for you to worry about it unless you're a C programmer.A library of time routines can convert between this internalrepresentation and more usable representations; see the UNIXmanual page for <EMCLASS="emphasis">ctime</EM>(3).</P><DIVCLASS="sect1info"><PCLASS="SECT1INFO">- <SPANCLASS="authorinitials">ML</SPAN></P></DIV></DIV><DIVCLASS="htmlnav"><P></P><HRALIGN="LEFT"WIDTH="515"TITLE="footer"><TABLEWIDTH="515"BORDER="0"CELLSPACING="0"CELLPADDING="0"><TR><TDALIGN="LEFT"VALIGN="TOP"WIDTH="172"><ACLASS="SECT1"HREF="ch51_01.htm"TITLE="51.1 We Are Finally Getting to the Bottom of the Bucket "><IMGSRC="gifs/txtpreva.gif"SRC="gifs/txtpreva.gif"ALT="Previous: 51.1 We Are Finally Getting to the Bottom of the Bucket "BORDER="0"></A></TD><TDALIGN="CENTER"VALIGN="TOP"WIDTH="171"><ACLASS="book"HREF="index.htm"TITLE="UNIX Power Tools"><IMGSRC="gifs/txthome.gif"SRC="gifs/txthome.gif"ALT="UNIX Power Tools"BORDER="0"></A></TD><TDALIGN="RIGHT"VALIGN="TOP"WIDTH="172"><ACLASS="SECT1"HREF="ch51_03.htm"TITLE="51.3 ASCII Characters: Listing and Getting Values "><IMGSRC="gifs/txtnexta.gif"SRC="gifs/txtnexta.gif"ALT="Next: 51.3 ASCII Characters: Listing and Getting Values "BORDER="0"></A></TD></TR><TR><TDALIGN="LEFT"VALIGN="TOP"WIDTH="172">51.1 We Are Finally Getting to the Bottom of the Bucket </TD><TDALIGN="CENTER"VALIGN="TOP"WIDTH="171"><ACLASS="index"HREF="index/idx_0.htm"TITLE="Book Index"><IMGSRC="gifs/index.gif"SRC="gifs/index.gif"ALT="Book Index"BORDER="0"></A></TD><TDALIGN="RIGHT"VALIGN="TOP"WIDTH="172">51.3 ASCII Characters: Listing and Getting Values </TD></TR></TABLE><HRALIGN="LEFT"WIDTH="515"TITLE="footer"><IMGSRC="gifs/smnavbar.gif"SRC="gifs/smnavbar.gif"USEMAP="#map"BORDER="0"ALT="The UNIX CD Bookshelf Navigation"><MAPNAME="map"><AREASHAPE="RECT"COORDS="0,0,73,21"HREF="../index.htm"ALT="The UNIX CD Bookshelf"><AREASHAPE="RECT"COORDS="74,0,163,21"HREF="index.htm"ALT="UNIX Power Tools"><AREASHAPE="RECT"COORDS="164,0,257,21"HREF="../unixnut/index.htm"ALT="UNIX in a Nutshell"><AREASHAPE="RECT"COORDS="258,0,321,21"HREF="../vi/index.htm"ALT="Learning the vi Editor"><AREASHAPE="RECT"COORDS="322,0,378,21"HREF="../sedawk/index.htm"ALT="sed & awk"><AREASHAPE="RECT"COORDS="379,0,438,21"HREF="../ksh/index.htm"ALT="Learning the Korn Shell"><AREASHAPE="RECT"COORDS="439,0,514,21"HREF="../lrnunix/index.htm"ALT="Learning the UNIX Operating System"></MAP></DIV></BODY></HTML>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -