Linux kernel 2.0.30
slackware installation
You may have noticed that the time on your Linux machine drifts, that is, it becomes inaccurate after several hours/days/weeks of operation without rebooting. Here is how to fix that and why it happens.
I found this posted on some newsgroup.
Question 6.2. My clock is very wrong.So the above seemed to work for me. I wrote a script:There are two clocks in your computer. The hardware (CMOS) clock runs even when the computer is off and is used to when the system starts up and by DOS (if you use it). The ordinary system time, shown and set by date, is maintained by the kernel while Linux is running.
You can display the CMOS clock time, or set either clock from the other, with /sbin/clock program - see man 8 clock.
There are various other programs that can correct either or both clocks for systematic drift or transfer time across the network. Some of them may already be installed on your system. Try looking at or for adjtimex (corrects for drift), netdate and getdate (simply get the time from the network) or xntp (accurate fully-featured network time daemon).
This script will reset the system clock to the hardware clock setting. I made an entry in my crontab so that it runs automatically every hour. (see All About Cron )#! /bin/sh # # This program will run every hour (via cron) # it simply sets the system clock time to the hardware # clock time. # # for more info. # man 8 clock /sbin/clock -s exit 1
The question you may be asking at this point is, why does the date command return a different time than the clock command if the clock command is more accurate? Why does Linux bother with two different clocks? The answer to this is, I think, because it takes a lot longer to get the time from the hardware clock (clock command) than it does from the system clock (date command). In situations where you need to get the date very often, very rapidly, the clock command would be too slow.
Return to Gene's Home Page
Return to Gene's Random Unix Crap