[mdlug] Can the date stamp on a file be ahead of the clock

Robert Meier eaglecoach at wwnet.com
Thu Sep 6 23:20:01 EDT 2007


Ray, R.,

R.>> I am seeing a puzzling behavior in a linux machine at work. 
R.>> See the series of commands and the responses below
R.>>
R.>> kez at vision->uname -a
R.>>   Linux vision 2.6.16.21-0.8-smp #1 SMP Mon Jul 3 18:25:39 UTC 2006 ...
R.>> kez at vision->touch tt1
R.>> kez at vision->ls -l tt1
R.>>   -rw-r--r-- 1 kez hks 0 2007-09-06 14:49 tt1
R.>> kez at vision->date
R.>>   Thu Sep  6 14:42:16 EDT 2007

Ray> Linux, and probably other unixes, [keep] a system clock separate
Ray> from the hardware clock. ...
Ray> pts/3 # hwclock;date
Ray>   Thu Sep  6 15:05:33 2007  -0.585800 seconds
Ray>   Thu Sep  6 15:05:32 EDT 2007
Ray> pts/3 # date 09061515
Ray>   Thu Sep  6 15:15:00 EDT 2007
Ray> pts/3 # hwclock;date
Ray>   Thu Sep  6 15:06:12 2007  -0.305832 seconds
Ray>   Thu Sep  6 15:15:03 EDT 2007
Ray> pts/3 # touch foo
Ray> pts/3 # ls -l foo
Ray>   -rw-r--r--  1 root root 0 Sep  6 15:15 foo
Ray> It seems that, on my system at least,
Ray>   the hardware clock is used for file system time stamps.

I assume you meant to say "the system clock is used for file system
time stamps", as the file timestamp matched the date(1) setting
in your example above.
     "date - print or set the system date and time"
	   -- date(1)

Ray> I've read the relevant man pages repeatedly and still don't
Ray> really see the point of keeping two different clocks. I just
Ray> keep mine synchronized. First I use the date command to set
Ray> the system clock, then I run (as root of course):
Ray>    ->hwclock --systohc

The reason for the two clocks is convenience, performance and
volatility.  The hardware clock keeps time even when the system
is shutdown.   The system clock is available to the kernel (and
its filesystem drivers) millions of times per second if necessary
without the overhead of an i/o interface.

You can operate a unix system without a hardware clock,
if you simply set the system clock from another source (e.g.
network time server) each time you boot.

Accurate time is the defacto standard for coordinating network services
like email, source file sharing and remote makes.

A hardware clock, consulted at boot (and otherwise occasionally)
is so cheap a motherboard acccessory, that its rare to find a
motherboard without one.



R.>> How could this be? I did not think this was possible...

I'm not sure what "this" is.  Do you mean a timestamp in the future?

An idiom for setting a (low-resolution) timeout in a script
is to set a future timestamp and check for passage.

    bash> touch --date '+1day' /tmp/timelimit
    bash> while test /tmp/timelimit -nt log
        > do something-repeatable > log
        > done

Anything (e.g. something repeatable) scriptable can use flexible
time specifications without having to implement parsing (already
supplied by date(1)).

Hopefully helpful,
-- 
DrB




More information about the mdlug mailing list