-   Linux - Software (
-   -   hardware clock time differs from system time after setting (

maxgsp 02-26-2009 09:40 AM

hardware clock time differs from system time after setting
I'm setting the hardware clock on RHEL 5.1 system using /sbin/hwclock --systohc. After setting the clock I issue a date command followed by a /sbin/hwclock --show from within a script to get fast resolution and I see that the hardware clock precedes the system time on average by .5 seconds. Does anyone have any idea why this would happen and how to fix it? I would think the clock should be identical after setting. thanks

H_TeXMeX_H 02-28-2009 03:21 AM

I wrote this script for setting the system time, I'm assuming that's what you're trying to do, this include the right commands in the right order:


# set the system time and date

# make sure we are root
if test ~ != '/root'
        echo 'ERROR: You must be root to run this script' >&2
        # fail
        exit 1

# read user input
printf 'Enter month as ## => '
read month
printf 'Enter day as ## => '
read day
printf 'Enter year as #### => '
read year
printf 'Enter hour out of 24 as ## => '
read hour
printf 'Enter minute as ## => '
read minute
printf 'Enter second as ## => '
read second
echo "Press <Enter> when you want to set the time to $month/$day/$year $hour:$minute:$second"
read dummy

# set date and time, and fix hwclock
date -s "$month/$day/$year $hour:$minute:$second"
/sbin/hwclock -r
/sbin/hwclock --adjust
/sbin/hwclock --systohc

echo 'System time is set. Settings will be in full effect on next reboot.'

# success
exit 0

jlinkels 02-28-2009 07:15 AM

Do you mean that the OS clock lags the hw clock by a constant 500 ms? It can have a number of reasons, including the resolution used by the various programs. If you are interested in the exact time, why don't you use ntp. The hardware clock is something to keep the time while the computer is switched off, nothing more. The time of the running OS is considered the correct time and should be used by processes.


All times are GMT -5. The time now is 10:03 PM.