Linux – Is ‘Sleep’ Based on the System Clock or on Time Elapsed?

linuxosxsleep

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?

Best Answer

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.

Related Question