收到 ntp 调整通知 [英] Get notified of ntp adjustments

查看:44
本文介绍了收到 ntp 调整通知的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的情况很奇怪,我需要一些关于 NTP 时间调整的指导.

I am in a weird situation and I need some direction with NTP time adjustments.

我有一台运行 NTP 守护程序的 PC(Red Hat),这台 PC 使用我 LAN 上的 Stratum 2 时间服务器调整时间.

I have a PC (Red Hat) that runs NTP daemon and this PC adjusts its time with a Stratum 2 time server on my LAN.

我的 PC 还通过串行端口 (RS-232) 连接到 DVR.这个设备和我的电脑时间需要同步.

My PC is also connected to a DVR over serial port (RS-232). This device and my PC time needs to in synchronization.

但是一段时间后,我的 PC 和 DVR 的时钟开始漂移,所以我需要一种方法来检测我的 PC 上的时间调整并将相同的调整应用到 DVR.

However after some time the clocks of my PC and DVR begin to drift away, so I need a way of detecting time adjustment on my PC and apply same adjustment to DVR as well.

有没有办法做到这一点?

Is there any way of doing this ?

我希望找到一种在操作系统级别订阅某种事件的方法,以更改 Red Hat 上的系统时钟.(如果这对于 RedHat 来说是可能的)

I am hoping to find a way of subscribing to some kind of event at OS level for system clock changes on Red Hat. (If this is possible at all for RedHat)

似乎可以在 Windows 上使用 SystemEvents.TimeChanged 事件,但我在 RedHat 上找不到使用 C++ 的对应事件.

It seems it is possible on Windows with SystemEvents.TimeChanged event but I could not find a counterpart on RedHat using C++.

感谢任何帮助.

推荐答案

大部分时间 NTP 服务器不会对系统时钟进行离散调整,它只会使用 adjtime,努力控制漂移率.NTP 服务器可能会相当连续地执行此操作,并且不会在每次进行调整时通知您.

Most of the time the NTP server does not make discrete adjustments to the system clock, it only slows it down or speeds it up using adjtime, in an effort to keep the drift rate under control. The NTP server might be doing this fairly continuously, and it will not tell you every time it makes an adjustment.

即使 NTP 服务器在进行调整时告诉您,该信息对您也没有用处.您的 DVR 的时钟由不同的硬件驱动,因此具有不同的漂移率,需要在不同的时间进行不同的调整.理想情况下,这将由 DVR 上的 NTP 守护程序完成!

Even if the NTP server told you whenever it made adjustments, that information is not useful for you. Your DVR's clock is driven by different hardware and therefore has a different drift rate and would require a different set of adjustments at different times. Ideally this would be done by an NTP daemon on the DVR!

NTP 守护进程在某些情况下会导致时钟跳动.它可能发生在启动时或时钟偏离时,但这应该是非常罕见的事件.它在执行此操作时可能会发出一条日志消息,因此一种可能性是查看日志.另一种可能性是不时比较 clock_gettime(CLOCK_REALTIME)clock_gettime(CLOCK_MONOTONIC) 的结果.当您注意到这两个时钟之间的增量发生了变化时,一定是因为有人使系统时间跳跃.但请注意:结果会很不稳定,因为从您获取其中一个时钟的那一刻到获取另一个时钟的那一刻起,所经过的时间不可预测且可变.

The NTP daemon does under some circumstances cause a jump in the clock. It may happen at startup or if the clock gets way off, but this should be a very rare event. It probably emits a log message when it does this, so one possibility would be to watch the logs. Another possibility would be to compare the results from clock_gettime(CLOCK_REALTIME) and clock_gettime(CLOCK_MONOTONIC) from time to time. When you notice that the delta between these two clocks has changed, it must be because someone made the system time jump. But beware: the results will be jittery because an unpredictable and variable amount of time elapses from the moment you fetch one of the clocks until the moment you fetch the other one.

根据您的需要,您可以通过忽略系统时间并仅使用 clock_gettime(CLOCK_MONOTONIC) 与 DVR 同步来实现您的需要.那个时钟保证不会跳.但要小心!(再次?!哈哈!)我相信 CLOCK_MONOTONIC 在 NTP 守护进程的指导下仍然可以减慢和加速.

Depending on your needs, you might be able to achieve what you need by ignoring the system time and using only clock_gettime(CLOCK_MONOTONIC) for synchronizing with the DVR. That clock is guaranteed not to jump. But beware! (again?! haha!) I believe CLOCK_MONOTONIC may still slow down and speed up under the direction of the NTP daemon.

这篇关于收到 ntp 调整通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆