Altering the system clock

Discussion in 'C Programming' started by jny0, Jan 10, 2011.

  1. jny0

    jny0 Guest

    Hi,

    I've submitted this in c.moderated as well (but it hasn't yet made it
    to be posted), so sorry if you're thinking you've read this already.

    I need some code to write a new time to the system clock. I can draw
    the time from it easily enough, but need to be able to sync the system
    with a server time. How can I do this?

    Regards,
    JNY
     
    jny0, Jan 10, 2011
    #1
    1. Advertising

  2. jny0

    Seebs Guest

    On 2011-01-10, jny0 <> wrote:
    > I've submitted this in c.moderated as well (but it hasn't yet made it
    > to be posted), so sorry if you're thinking you've read this already.


    It got rejected.

    > I need some code to write a new time to the system clock. I can draw
    > the time from it easily enough, but need to be able to sync the system
    > with a server time. How can I do this?


    You can't in portable C. A way to do it may exist on any given systems,
    but on many systems, the answer will be "you can't, have the system
    administrator do it for you."

    -s
    --
    Copyright 2010, all wrongs reversed. Peter Seebach /
    http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures
    http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated!
    I am not speaking for my employer, although they do rent some of my opinions.
     
    Seebs, Jan 10, 2011
    #2
    1. Advertising

  3. jny0

    Nobody Guest

    On Mon, 10 Jan 2011 02:50:14 -0800, jny0 wrote:

    > I need some code to write a new time to the system clock. I can draw
    > the time from it easily enough, but need to be able to sync the system
    > with a server time. How can I do this?


    You should assume that you cannot do this.

    If you just need to synchronise your application to a remote server, you
    should leave the system clock alone and just store the difference between
    the local system time and the server's time.

    On Unix, adjusting the system clock typically requires superuser privilege
    (or CAP_SYS_TIME on systems with capabilities). But that's only the
    minimum kernel-imposed requirement; there may be additional constraints.

    E.g. if the system is running ntpd, ntpd will try to maintain the system
    clock, and will try to correct any adjustments which you make to it. Also,
    there may be reasons why the system needs to be accurately (and
    demonstrably) synchronised to a known time source, and messing with that
    may result in contractual or even statutory liability (even if they clock
    remains accurate, you may not be able to adequately prove it).

    Making instantaneous adjustments to the system clock is a very bad idea,
    as it will break anything which tries to perform rate-of-change
    calculations. If the time goes backwards, files will suddenly have
    timestamps in the future.

    For this reason, most modern Unix systems have interfaces such as
    adjtime(), where you specify a desired change and the kernel makes the
    system clock run slightly (like, 1%) fast or slow until the desired change
    has been completed.
     
    Nobody, Jan 11, 2011
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Valentin Tihomirov

    Are clock and divided clock synchronous?

    Valentin Tihomirov, Oct 23, 2003, in forum: VHDL
    Replies:
    11
    Views:
    3,333
    louis lin
    Oct 28, 2003
  2. Replies:
    4
    Views:
    739
    Peter Alfke
    Apr 27, 2006
  3. Replies:
    5
    Views:
    2,205
    Ricardo
    Jun 23, 2006
  4. himassk
    Replies:
    1
    Views:
    1,242
    Paul Uiterlinden
    May 16, 2007
  5. pankaj.goel
    Replies:
    6
    Views:
    948
    pankaj.goel
    Nov 25, 2008
Loading...

Share This Page