Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
boot time in /proc/stat isn't constant - alternatives?
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Kernel & Hardware
View previous topic :: View next topic  
Author Message
fikiz
Apprentice
Apprentice


Joined: 07 Mar 2005
Posts: 282
Location: Italy

PostPosted: Tue Feb 23, 2016 3:35 pm    Post subject: boot time in /proc/stat isn't constant - alternatives? Reply with quote

Hello everybody.

I realized that the btime value in /proc/stat isn't constant. Every now and then it drifts forward 1 second at a time.
Searching on the net, I found people complaining about that since Linux 2.2 so... It must be ok and I don't look for bug fixes or whatever. I would be fun know why this drift happens, but it's not my point.

What I'm looking for is a reliable way to identify reboots inside a script launched by cron. It's easy, I can write the btime value down into a file once at every boot and read that file from my script.

But here I would like the simplest possible solution: get this information directly from the OS or the kernel. There is something somewhere inside /proc or /sys that it changes at every boot and stays constant until the next reboot?

Thanks for any hint.

bye
Back to top
View user's profile Send private message
szatox
Veteran
Veteran


Joined: 27 Aug 2013
Posts: 1747

PostPosted: Tue Feb 23, 2016 4:53 pm    Post subject: Reply with quote

It seems you're looking for this:
Code:
uptime -s
Back to top
View user's profile Send private message
fikiz
Apprentice
Apprentice


Joined: 07 Mar 2005
Posts: 282
Location: Italy

PostPosted: Wed Feb 24, 2016 11:32 am    Post subject: Reply with quote

szatox:
I took my time to check uptime -s stability, but it suffers a slow drift too, albeit not the same as btime in /proc/stat.
I also realized that the drift is somehow related to suspend/resume cycles.

Thank you anyway.
Back to top
View user's profile Send private message
szatox
Veteran
Veteran


Joined: 27 Aug 2013
Posts: 1747

PostPosted: Wed Feb 24, 2016 4:31 pm    Post subject: Reply with quote

Good point, now as you mentioned it I checked it as well, and the boot time suddenly got delayed by 1 second.
However, you can still do that in the simple and ugly way: create a timestamp file under /run during boot process.
A 1 line script in /etc/local.d/ will do the trick.
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Kernel & Hardware All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum