3

Is 'sleep' based on the system clock or on time elapsed?

For example, if you execute:

sleep 1200

And immediately suspend your system for 10 minutes, will it end in another 10 minutes, or will it continue to wait for the full 20 minutes?

  • 1
    I don't think suspending the system affects the system clock like that; perhaps a direct change of time would be a better example? – Michael Homer Jul 2 '19 at 20:49
4

Well I guess it was easy enough to test. After initiating a 5 minute sleep, I suspended the system for about 2 minutes. The answer?

Sleep is calculated using elapsed time of the process, not clock time.

date; sleep 300; date
Tue Jul  2 20:58:41 EDT 2019
Tue Jul  2 21:05:28 EDT 2019

This may have been predictable since man sleep(3) says:

System activity may lengthen the sleep by an indeterminate amount.

Which kind of implies the amount of time is internal to the sleep process.

| improve this answer | |

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.