Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!goblin1!goblin.stu.neva.ru!postnews.google.com!news2.google.com!Xl.tags.giganews.com!border1.nntp.dca.giganews.com!nntp.giganews.com!local2.nntp.dca.giganews.com!news.giganews.com.POSTED!not-for-mail NNTP-Posting-Date: Mon, 19 Dec 2011 17:30:03 -0600 Message-ID: From: William Ahern 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> User-Agent: tin/1.8.3-20070201 ("Scotasay") (UNIX) (OpenBSD/4.9 (amd64)) Date: Mon, 19 Dec 2011 15:15:32 -0800 Lines: 36 X-Usenet-Provider: http://www.giganews.com X-Trace: sv3-7KeGQOMIWGYoH7uMhndWriIEOiVO1eJzYne8IIXgR6TJB9IeDYk3c9Ys+0/GimJAmKYV982cmyMaoSf!J35KeN06EHipyVYpbT9BjiX4J3flpT1mVQMXy6M2xUavLZqsLfdXSv/4FLfa/P4Rtw== X-Complaints-To: abuse@giganews.com X-DMCA-Notifications: http://www.giganews.com/info/dmca.html X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly X-Postfilter: 1.3.40 X-Original-Bytes: 2745 Xref: x330-a1.tempe.blueboxinc.net comp.os.linux.development.system:351 comp.unix.programmer:1835 Lew Pitcher 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()).