Why not just teach your server admin(s) to sync their clocks using NTP? Then you don't have a problem.....

As to the approach I would probably run a demon that just did:

#!/usr/bin/perl my $start = time(); my $sleep = 600; my $how_much = 5; my $offset_file = '/tmp/offset.txt'; my $offset = 0; print_to_file( $offset ); while ( 1 ) { sleep($sleep); my $now = time(); if ( abs ( $start + $sleep - $now ) > $how_much ) { $offset = $start + $sleep - $now; print_to_file( $offset ); } $start = time(); } sub print_to_file { my $offset = shift; `echo $offset > $offset_file`; }

In this approach we allow use 5 seconds of change in 10 minutes as our significance level. If the time has changed by more than this then someone has probably changed the clock so we write the offset to the offset file.... This is the general approach used by time limited software for instance that gets upset if you change the clock.

Just check the offset file as needed. This should be less load and is not dependent on sleep(1) being exactly 1,000 msec. If it is not your clock will drift considerably over time.

cheers

tachyon

s&&rsenoyhcatreve&&&s&n.+t&"$'$`$\"$\&"&ee&&y&srve&&d&&print


In reply to Re: system-clock-safe timers without time()? by tachyon
in thread system-clock-safe timers without time()? by edan

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.