`Ntpd` устанавливает аппаратные часы?


11

ntpdУстановлены ли аппаратные часы?

ntpdУстанавливаются ли аппаратные часы, если я передаю -qопцию (имеется в виду одноразовая коррекция)?

Linux 3.5.6, ntp 4.2.6.p5.

Здесь написано, что ntpd синхронизирует системные часы с аппаратными средствами каждые 11 минут, но я не могу найти ссылку на это в руководстве ntpd.

ntpd 

1
Пожалуйста, смотрите этот вопрос: serverfault.com/questions/337930/…
Карлсон

@ Карлсон: ОК. Если демон ntpd заставляет ядро ​​синхронизировать аппаратные часы каждые 11 минут, но что ntpd -q?

Является ли ntpdработает?
Карлсон

Ответы:


5

Аналогичный вопрос был задан на Serverfault.com . Это был ответ.

Со hwclockстраницы руководства на RHEL 4.6:

This mode (we'll call it "11 minute mode") is off until something turns it on.  The ntp
daemon  xntpd  is  one thing  that  turns  it on.  You can turn it off by running
anything, including hwclock --hctosys, that sets the System Time the old fashioned way.

To see if it is on or off, use the command adjtimex --print and look at the value of
"status".  If the "64" bit of this number (expressed in binary) equal to 0, 11 minute mode 
is on.  Otherwise, it is off.

Таким образом, благодаря тому, что вы бежите, hwclock --setвы, вероятно, отключили его. По тому же признаку вы можете проверить вывод adjtimex --printдля подтверждения.


-1

Убедитесь сами (следующий скрипт отображает текущее «состояние времени» практически в реальном времени, в то же время регистрируя внезапные изменения значения)

#!/bin/sh
set -eu

get_time() {
    local line="$1"
    timedatectl \
        | sed -nE $line'p' \
        | sed -E 's/.* ([0-9]+):([0-9]+):([0-9]+).*/\1\2\3/'
}


get_time_status() {
    adjtimex --print \
        | grep -F status \
        | awk '{print "obase=2;" $2}' \
        | bc
}


num_diff() {
    local a="$1" b="$2"
    echo "ah = ${a:0:2}; am = ${a:2:2}; as = ${a:4:2}
        bh = ${b:0:2}; bm = ${b:2:2}; bs = ${b:4:2}
        a = ah * 60 * 60 + am * 60 + as
        b = bh * 60 * 60 + bm * 60 + bs
        if (a > b) a - b else b - a" | bc
}


print_line() {
    local f1="$1" f2="$2"
    printf "%20s %-$(($(tput cols) - 21))s\n" "$f1" "$f2"
}


localt=
universalt=
rtct=
ntp_enabled=
ntp_synchronized=
time_status=

localt_prv="$(get_time 1)"
universalt_prv="$(get_time 2)"
rtct_prv="$(get_time 3)"
ntp_enabled_prv="$(timedatectl | grep -E 'NTP enabled' | awk '{print $3}')"
ntp_synchronized_prv="$(timedatectl | grep -E 'NTP synchronized' | awk '{print $3}')"
time_status_prv="$(get_time_status)"

while true; do
    localt="$(get_time 1)"
    universalt="$(get_time 2)"
    rtct="$(get_time 3)"
    ntp_enabled="$(timedatectl | grep -E 'NTP enabled' | awk '{print $3}')"
    ntp_synchronized="$(timedatectl | grep -E 'NTP synchronized' | awk '{print $3}')"
    time_status="$(get_time_status)"

    if [ "$(num_diff $localt $localt_prv)" -gt 5 ]; then
        print_line "[$(date +%H:%M:%S)]" "localt: $localt_prv -> $localt"
    fi
    if [ "$(num_diff $universalt $universalt_prv)" -gt 5 ]; then
        print_line "[$(date +%H:%M:%S)]" "universalt: $universalt_prv -> $universalt"
    fi
    if [ "$(num_diff $rtct $rtct_prv)" -gt 5 ]; then
        print_line "[$(date +%H:%M:%S)]" "rtct: $rtct_prv -> $rtct"
    fi
    if [ "$ntp_enabled" != "$ntp_enabled_prv" ]; then
        print_line "[$(date +%H:%M:%S)]" "ntp_enabled: $ntp_enabled_prv -> $ntp_enabled"
    fi
    if [ "$ntp_synchronized" != "$ntp_synchronized_prv" ]; then
        print_line "[$(date +%H:%M:%S)]" "ntp_synchronized: $ntp_synchronized_prv -> $ntp_synchronized"
    fi
    if [ "$time_status" != "$time_status_prv" ]; then
        print_line "[$(date +%H:%M:%S)]" "time_status: $time_status_prv -> $time_status"
    fi

    print_line local: "$localt"
    print_line universal: "$universalt"
    print_line rtc: "$rtct"
    print_line 'NTP enabled:' "$ntp_enabled"
    print_line 'NTP synchronized:' "$ntp_synchronized"
    print_line 'time status:' "$time_status"

    sleep 1

    localt_prv="$localt"
    universalt_prv="$universalt"
    rtct_prv="$rtct"
    ntp_enabled_prv="$ntp_enabled"
    ntp_synchronized_prv="$ntp_synchronized"
    time_status_prv="$time_status"

    printf '\033[6A'
done

5
Дайте содержательное объяснение, пожалуйста.
MTK
Используя наш сайт, вы подтверждаете, что прочитали и поняли нашу Политику в отношении файлов cookie и Политику конфиденциальности.
Licensed under cc by-sa 3.0 with attribution required.