0

我正在调用 ntp_gettime() 并且它按预期执行但是如果我杀死 ntpd 我仍然会得到正确的行为,并且我的返回值没有显示任何问题。这表明 ntp_gettime() 不会调用 ntpd,我相信这是正在发生的事情。

我正在尝试检查 ntpd 是否仍然正常运行并且它仍然具有有效的连接。我现在假设 ntpd 根据定义的时间间隔更新系统,并且 ntp_gettime() 调用仅调用系统。

我的问题是可以使用 ntp_gettime() 来确定 ntpd 是否正在运行并且服务器连接仍然有效并且我只是在某个地方犯了错误吗?如果没有,有没有办法做到这一点?

4

3 回答 3

0

你的问题的答案是“不”。这不是 NTP 服务器的接口,不能用来确定 NTP 服务器的状态。这是完全不同的东西。根据 glibc 文档

ntp_gettime 和 ntp_adjtime 函数提供了一个接口来监视和操作系统时钟以保持高精度时间。例如,您可以微调时钟速度或将其与另一个时间源同步。

这些功能的典型使用是由实现网络时间协议的服务器来同步多个系统的时钟和高精度时钟。

换句话说,这就是 NTP 服务器本身用来与内核对话、处理业务的东西。

于 2019-12-15T15:11:57.530 回答
0

检查守护程序操作

ntpctl is a program to display information about the running ntpd daemon, the below command will give you info about how many servers the daemon is syncing with, the status of the system clock if it's synced/unsynced and the clock offset. For further information see the manpage of ntpctl https://man.openbsd.org/ntpctl. Openntpd package brings you the ntpctl program.

ntpctl -s all
于 2019-12-16T04:45:30.957 回答
0

The way I ended up doing it is by using a pipe to make a ntpstat call and processing the output. That is I check for unsynchronised, synchronised, and the absence of synchronised (after checking for unsynchronised) and act accordingly based on the results above.

If there is a better way to get the same result, because I think this is messy, please let me know.

于 2019-12-16T13:12:29.653 回答