Is sleep(3) effected by time changes?
It’s an interesting question. I tried it; it isn’t. Here’s my guess at an explanation:
sleep(3) is implemented internally on most systems as alarm(2) and sigsuspend(2). This means that this is an in-kernel question, not a userspace question. However, we know from clock_gettime(3) that the kernel has multiple internal clocks. CLOCK_MONOTONIC is defined as:
Clock that cannot be set and represents monotonic time since some unspecified starting point.
This must be what’s used for alarm(), which makes sense.
On a related note:
Those annoying programs that behave very oddly when you change the system time are broken. They’re using gettimeofday(2) or something that derives from it (i.e. time(2)) instead of properly calling clock_gettime(CLOCK_MONOTONIC).