set system time: clock_settime() or settimeofday() ? - Linux

This is a discussion on set system time: clock_settime() or settimeofday() ? - Linux ; I am porting code from Digital Unix (tru64) to Red Hat Linux 4.1. In Digital there is a function setclock() that sets the system time. Its semantics are very similar to the call clock_settime() available in Linux. However, I have ...

+ Reply to Thread
Results 1 to 3 of 3

Thread: set system time: clock_settime() or settimeofday() ?

  1. set system time: clock_settime() or settimeofday() ?

    I am porting code from Digital Unix (tru64) to Red Hat Linux 4.1.
    In Digital there is a function setclock() that sets the system time.
    Its semantics are very similar to the call clock_settime() available
    in Linux. However, I have three questions:

    1) any thoughts about which Clock ID to specify to clock_settime()? I
    imagine CLOCK_REALTIME?
    2) The constants (e.g. CLOCK_REALTIME) are not defined by my usual
    compiler options. Looking in bits/time.h it appears I may need
    __USE_POSIX199309 defined - is there any high-level #define I should
    use to get this?
    3) Because of above issues, I wonder if I should just use
    settimeofday()? Are there any issues or differences (apart from lack
    of nanosecond precision which I do not require) ?

    TIA
    Mark


  2. Re: set system time: clock_settime() or settimeofday() ?

    On a sunny day (15 Feb 2007 06:15:02 -0800) it happened
    mark.bergman@thales-is.com wrote in
    <1171548902.871075.46920@k78g2000cwa.googlegroups.c om>:

    >I am porting code from Digital Unix (tru64) to Red Hat Linux 4.1.
    >In Digital there is a function setclock() that sets the system time.
    >Its semantics are very similar to the call clock_settime() available
    >in Linux. However, I have three questions:
    >
    >1) any thoughts about which Clock ID to specify to clock_settime()? I
    >imagine CLOCK_REALTIME?
    >2) The constants (e.g. CLOCK_REALTIME) are not defined by my usual
    >compiler options. Looking in bits/time.h it appears I may need
    >__USE_POSIX199309 defined - is there any high-level #define I should
    >use to get this?
    >3) Because of above issues, I wonder if I should just use
    >settimeofday()? Are there any issues or differences (apart from lack
    >of nanosecond precision which I do not require) ?
    >
    >TIA
    >Mark


    # set system clock
    # NIST primary
    /usr/sbin/ntpdate 132.163.4.102
    # NIST backup
    #/usr/sbin/ntpdate 207.200.81.113

    # sys time to hardware clock
    hwclock --systohc

    # display the hardware clock
    hwclock --show



  3. Re: set system time: clock_settime() or settimeofday() ?

    On Feb 15, 2:15 pm, mark.berg...@thales-is.com wrote:
    > I am porting code from Digital Unix (tru64) to Red Hat Linux 4.1.
    > In Digital there is a function setclock() that sets the system time.
    > Its semantics are very similar to the call clock_settime() available
    > in Linux. However, I have three questions:
    >
    > 1) any thoughts about which Clock ID to specify to clock_settime()? I
    > imagine CLOCK_REALTIME?
    > 2) The constants (e.g. CLOCK_REALTIME) are not defined by my usual
    > compiler options. Looking in bits/time.h it appears I may need
    > __USE_POSIX199309 defined - is there any high-level #define I should
    > use to get this?


    Either of the following will work:
    #define _GNU_SOURCE
    #define _XOPEN_SOURCE 500
    #define _POSIX_C_SOURCE 199309

    --
    Bill Pursell





+ Reply to Thread