Groups | Search | Server Info | Login | Register


Groups > comp.os.linux.development.system > #351

Re: Getting time of last reboot on Linux

Message-ID <k5t4s8-sr2.ln1@wilbur.25thandClement.com> (permalink)
From William Ahern <william@wilbur.25thandClement.com>
Subject Re: Getting time of last reboot on Linux
Newsgroups comp.os.linux.development.system, comp.unix.programmer
References <4c0afddf-5e6e-41f5-b8d2-b65afcc4ee29@z1g2000vbx.googlegroups.com> <RjqHq.27421$c27.19904@newsfe22.iad>
Date 2011-12-19 15:15 -0800

Cross-posted to 2 groups.

Show all headers | View raw


Lew Pitcher <lpitcher@teksavvy.com> wrote:
> On December 18, 2011 12:35, in comp.os.linux.development.system,
> alex.vinokur@gmail.com wrote:
> > Hi,
> > 
> > Is there any sytem call (preferable) or shell-utility to get time of
> > last reboot on Linux?

> The who(1) command will tell you this. Use the -b ("time of last system
> boot") option.

> For example:
>   ~ $ who -b
>          system boot  2011-11-07 11:41

> FWIW, the system boot time is recorded in the utmp file (see utmp(5) for
> details), and Linux supplies an API that allows processes to read records
> from the file (see getutent(3) for details).

Here's a scenario: init starts and the current time is recorded in utmp.
init runs the startup scripts, which runs an ntp client. ntp notices that
the clock is off... way off. The system time leaps forwards or backwards.

I believe on Linux and *BSD, uptime(3) and /proc/uptime (where available)
are monotonic counters with the start time as an epoch. If you subtract this
from a known good time, you get the wall time boot time. However, last time
I inquired with Google, 32-bit Linux had a wrapping issue with /proc/uptime
(and presumably uptime(3)). The uptime gives seconds, but is computed in
jiffies, which has a much higher resolution but overflows much
faster--400-something days on some 2.4 kernels.

clock_gettime(CLOCK_MONOTONIC) could prove useful, but the problem is
converting it to wall time. Also, CLOCK_MONOTONIC support can be hard to
come by sometimes. Linux 2.4 doesn't have it, and neither does OS X
(although it's easy to write an implementation for OS X using
mach_absolute_time()).

Back to comp.os.linux.development.system | Previous | NextPrevious in thread | Next in thread | Find similar


Thread

Getting time of last reboot on Linux Alex Vinokur <alex.vinokur@gmail.com> - 2011-12-18 09:35 -0800
  Re: Getting time of last reboot on Linux Steve Thompson <smt@vgersoft.com> - 2011-12-18 12:46 -0500
    Re: Getting time of last reboot on Linux Alex Vinokur <alex.vinokur@gmail.com> - 2011-12-18 10:12 -0800
      Re: Getting time of last reboot on Linux Volker Birk <bumens@dingens.org> - 2011-12-18 18:19 +0000
        Re: Getting time of last reboot on Linux Andrew Smallshaw <andrews@sdf.lonestar.org> - 2011-12-21 16:01 +0000
  Re: Getting time of last reboot on Linux Volker Birk <bumens@dingens.org> - 2011-12-18 18:18 +0000
  Re: Getting time of last reboot on Linux Lew Pitcher <lpitcher@teksavvy.com> - 2011-12-18 13:31 -0500
    Re: Getting time of last reboot on Linux Stephane CHAZELAS <stephane_chazelas@yahoo.fr> - 2011-12-18 21:48 +0000
      Re: Getting time of last reboot on Linux Barry Margolin <barmar@alum.mit.edu> - 2011-12-18 21:29 -0500
        Re: Getting time of last reboot on Linux Stephane CHAZELAS <stephane_chazelas@yahoo.fr> - 2011-12-19 12:59 +0000
    Re: Getting time of last reboot on Linux William Ahern <william@wilbur.25thandClement.com> - 2011-12-19 15:15 -0800
      Re: Getting time of last reboot on Linux Lew Pitcher <lpitcher@teksavvy.com> - 2011-12-19 19:20 -0500
        Re: Getting time of last reboot on Linux William Ahern <william@wilbur.25thandClement.com> - 2011-12-19 18:32 -0800
        Re: Getting time of last reboot on Linux gordonb.xm1tg@burditt.org (Gordon Burditt) - 2011-12-22 00:16 -0600
          Re: Getting time of last reboot on Linux Stefan Monnier <monnier@iro.umontreal.ca> - 2012-01-09 09:18 -0500
      Re: Getting time of last reboot on Linux Ivan Shmakov <oneingray@gmail.com> - 2011-12-20 11:48 +0700
  Re: Getting time of last reboot on Linux Richard Kettlewell <rjk@greenend.org.uk> - 2011-12-21 17:06 +0000
    Re: Getting time of last reboot on Linux gazelle@shell.xmission.com (Kenny McCormack) - 2012-02-09 17:25 +0000
      Re: Getting time of last reboot on Linux Richard Kettlewell <rjk@greenend.org.uk> - 2012-02-09 21:11 +0000

csiph-web