![]() |
Altering the system clock
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 |
Re: Altering the system clock
On 2011-01-10, jny0 <jny0@hotmail.com> 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 / usenet-nospam@seebs.net 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. |
Re: Altering the system clock
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. |
| All times are GMT. The time now is 05:34 AM. |
Powered by vBulletin®. Copyright ©2000 - 2013, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.