获取 ntp 调整通知

发布于 2024-12-05 13:37:23 字数 549 浏览 1 评论 0原文

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

我有一台运行 NTP 守护进程的 PC(Red Hat),这台 PC 通过 LAN 上的 Stratum 2 时间服务器调整其时间。

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

然而,一段时间后,我的 PC 和 DVR 的时钟开始偏离,所以我需要一种方法来检测我的 PC 上的时间调整,并对 DVR 进行相同的调整。

有什么办法可以做到这一点吗?

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

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

任何帮助表示赞赏。

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

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.

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

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 ?

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)

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

Any help is appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

南笙 2024-12-12 13:37:23

大多数时候,NTP 服务器不会对系统时钟进行离散调整,它只是使用 adjtime 减慢或加快时钟速度,以努力控制漂移率。 NTP 服务器可能会相当连续地执行此操作,并且不会在每次进行调整时告诉您。

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

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

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

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.

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!

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.

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.

清秋悲枫 2024-12-12 13:37:23

由于除了 Microsoft 的 API 更改之外,似乎没有真正解决此问题的方法,因此我添加了 功能请求。如果您也遇到同样的问题,请投票。

Since there doesn't seem to really be a solution to this problem short of an API change from Microsoft, I've added a feature request. Please upvote if you're having this same issue.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文