adjtimex can be used to query if the system time is synchronized, e.g. whether NTP is working or not. Example output of a machine where ntpd can't connect to any peers (status: UNSYNC, return value: 5 (clock not synchronized)): host ~ # busybox adjtimex; echo $? mode: 0 -o offset: 0 us -f freq.adjust: 2126708 (65536 = 1ppm) maxerror: 16000000 esterror: 16000000 status: 16449 (PLL | UNSYNC) -p timeconstant: 7 precision: 1 us tolerance: 32768000 -t tick: 10000 us time.tv_sec: 1619093972 time.tv_usec: 354882 return value: 5 (clock not synchronized) 0 Unfortunately this has to be parsed from the output because the return value is only printed and not actually returned. It would be useful if adjtimex had a flag for this purpose, e.g. -r to actually return the call's return value. This would allow scripts to use `adjtime -qr` to suppress the output and determine the synchronization state efficiently by examining the return code.
Does upstream do it?
(In reply to Denys Vlasenko from comment #1) No, unfortunately it doesn't either: host ~ # adjtimex -p; echo $? mode: 0 offset: 0 frequency: 246768 maxerror: 16000000 esterror: 15 status: 8257 time_constant: 9 precision: 1 tolerance: 32768000 tick: 10000 raw time: 1623078713s 98145560ns = 1623078713.098145560 return value = 5 0 I haven't found a bugtracker for the original adjtimex; it apparently originates from http://metalab.unc.edu/pub/Linux/system/admin/time and the last release was in 2009. There is a fork maintained by the current adjtimex Debian maintainer, so I've went ahead and filed essentially the same feature request there: https://github.com/rogers0/adjtimex/issues/4