Clocks in a Linux System

本文详细解释了Linux系统中硬件时钟与系统时间的区别与作用,硬件时钟独立于CPU运行且不受控制程序影响,而系统时间则由内核驱动,仅在Linux运行时有效。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

There are two main clocks in a Linux system:

       The Hardware Clock: This is a clock that runs independently of any control program running in the CPU and even when the machine is powered off.

       On an ISA system, this clock is specified as part of the ISA standard.  The control program can read or set this clock to a whole second, but the control
       program can also detect the edges of the 1 second clock ticks, so the clock actually has virtually infinite precision.

       This  clock  is commonly called the hardware clock, the real time clock, the RTC, the BIOS clock, and the CMOS clock.  Hardware Clock, in its capitalized
       form, was coined for use by hwclock because all of the other names are inappropriate to the point of being misleading.

       The System Time: This is the time kept by a clock inside the Linux kernel and driven by a timer interrupt.  (On an ISA machine, the  timer  interrupt  is
       part  of  the ISA standard).  It has meaning only while Linux is running on the machine.  The System Time is the number of seconds since 00:00:00 January
       1, 1970 UTC (or more succinctly, the number of seconds since 1969).  The System Time is not an integer, though.  It has virtually infinite precision.

       The System Time is the time that matters.  The Hardware Clock's basic purpose in a Linux system is to keep time when Linux is not running.  You  initial-
       ize  the  System Time to the time from the Hardware Clock when Linux starts up, and then never use the Hardware Clock again.  Note that in DOS, for which
       ISA was designed, the Hardware Clock is the only real time clock.

       It is important that the System Time not have any discontinuities such as would happen if you used the date(1L) program to set it  while  the  system  is
       running.  You can, however, do whatever you want to the Hardware Clock while the system is running, and the next time Linux starts up, it will do so with
       the adjusted time from the Hardware Clock.  You can also use the program adjtimex(8) to smoothly adjust the System Time while the system runs.

       A Linux kernel maintains a concept of a local timezone for the system.  But don't be misled -- almost nobody cares what timezone the kernel thinks it  is
       in.   Instead,  programs  that  care  about the timezone (perhaps because they want to display a local time for you) almost always use a more traditional
       method of determining the timezone: They use the TZ environment variable and/or the /usr/share/zoneinfo directory, as  explained  in  the  man  page  for
       tzset(3).   However,  some  programs  and  fringe  parts  of  the Linux kernel such as filesystems use the kernel timezone value.  An example is the vfat
       filesystem.  If the kernel timezone value is wrong, the vfat filesystem will report and set the wrong timestamps on files.

       hwclock sets the kernel timezone to the value indicated by TZ and/or /usr/share/zoneinfo when you set the System Time using the --hctosys option.

       The timezone value actually consists of two parts: 1) a field tz_minuteswest indicating how many minutes local time (not adjusted for  DST)  lags  behind
       UTC, and 2) a field tz_dsttime indicating the type of Daylight Savings Time (DST) convention that is in effect in the locality at the present time.  This
       second field is not used under Linux and is always zero.  (See also settimeofday(2).)
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值