Latest LQ Deal: Latest LQ Deals
Go Back > Forums > Linux Forums > Linux - Software
User Name
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.


  Search this Thread
Old 02-26-2009, 10:40 AM   #1
LQ Newbie
Registered: Jun 2004
Posts: 25

Rep: Reputation: 2
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
Old 02-28-2009, 04:21 AM   #2
LQ Guru
Registered: Oct 2005
Location: $RANDOM
Distribution: slackware64
Posts: 12,928
Blog Entries: 2

Rep: Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301
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
Old 02-28-2009, 08:15 AM   #3
LQ Guru
Registered: Oct 2003
Location: Bonaire, Leeuwarden
Distribution: Debian /Jessie/Stretch/Sid, Linux Mint DE
Posts: 5,195

Rep: Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043
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.



Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
System time vs Hardware time and Daylight Savings Time Toadman Linux - General 6 03-17-2007 09:12 AM
System time vs Hardware time and Daylight Savings Time Toadman Linux - Networking 6 03-16-2007 08:14 PM
Where does RH8 daily set system time to hardware clock time smartnorman Red Hat 1 05-24-2006 03:42 PM
Setting the system clock to a time server? orange400 Linux - General 4 06-13-2005 02:59 PM > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 06:00 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration