Azure linux uptime -s increasing

ppp asked:

Do you know why uptime -s increasing in Azure platform?

hostname@ubuntu:~$ date
Thu Jan  4 15:00:04 CET 2018
hostname@ubuntu:~$ uptime -s
2018-01-01 00:52:15

After 10 minutes:

hostname@ubuntu:~$ date
Thu Jan  4 15:10:18 CET 2018
hostname@ubuntu:~$ uptime -s
2018-01-01 00:52:24

hostname@ubuntu:~$ ps -Afl
F S UID PID PPID C PRI NI ADDR SZ WCHAN STIME TTY TIME CMD
4 S root 1 0 0 80 0 – 30225 – Jan01 ? 00:00:49 /sbin/init

This host works stable

My answer:


The apparent time that your system was booted, as shown by uptime -s, changed because the system clock changed.

Let us look at the source code for uptime, to see how it works.

    /* Get the current time and convert it to a double */
    gettimeofday(&tim, NULL);
    now = tim.tv_sec + (tim.tv_usec / 1000000.0);

We see here that it first gets the current time of day.

    /* Get the uptime and calculate when that was */
    uptime(&uptime_secs, &idle_secs);
    up_since_secs = (time_t) ((now - uptime_secs) + 0.5);

Next, it gets the actual uptime in seconds as reported by the kernel, and which would otherwise have been reported if you hadn’t used -s. It then subtracts that number of seconds from the current time, rounding to the nearest second.

Thus, if the system clock is adjusted, the output of -s will have a corresponding change.


View the full question and answer on Server Fault.

Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.