LinuxQuestions.org
View the Most Wanted LQ Wiki articles.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
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.

Notices

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

Rep: Reputation: 1
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
H_TeXMeX_H
Guru
 
Registered: Oct 2005
Location: $RANDOM
Distribution: slackware64
Posts: 12,928
Blog Entries: 2

Rep: Reputation: 1269Reputation: 1269Reputation: 1269Reputation: 1269Reputation: 1269Reputation: 1269Reputation: 1269Reputation: 1269Reputation: 1269
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:

Code:
#!/bin/sh
# set the system time and date

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

# 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
jlinkels
Senior Member
 
Registered: Oct 2003
Location: Bonaire
Distribution: Debian Wheezy/Jessie/Sid, Linux Mint DE
Posts: 4,234

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

jlinkels
 
  


Reply


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


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

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