6

I put my laptop to suspend mode, woke it up later, and now it shows uptime some 23 hours (with uptime), which is obviously not true. I suspect uptime simply returns the difference between the timestamp at boot and now.

Is there a way to show uptime excluding time spent in low power modes like suspend and hibernate?

1

You probably want to use the C function clock_gettime(CLOCK_MONOTONIC_RAW), which isn't presented by any utility (that I know of). I see an answer that gives a python example on how to access it, which might be easier than compiling a C program to do the same.

  • As said in the man page, the starting point of the clock is unspecified. To get the uptime, one would need to have the starting point at the boot. – vinc17 Dec 7 '14 at 23:58
  • I've heard that the monotonic clock gets initialized with the hardware time at the moment from which uptime is counted. Then the clock may diverge. I have no evidence for that right now: the only thing to rely on is that CLOCK_MONOTONIC won't jump back. – Tomasz Gandor Mar 17 '16 at 9:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.