Is sleep(3) effected by time changes?

This commit is contained in:
Ian Gulliver
2019-04-21 17:23:22 +00:00
parent c35ad33bd3
commit 0fa0ed4f63
4 changed files with 40 additions and 0 deletions

View File

@@ -0,0 +1,20 @@
<!--# set var="title" value="Is sleep(3) effected by time changes?" -->
<!--# set var="date" value="February 13, 2006" -->
<!--# include file="include/top.html" -->
<p>Its an interesting question. I tried it; it isnt. Heres my guess at an explanation:</p>
<p><a href="http://www.tin.org/bin/man.cgi?section=3&amp;topic=sleep">sleep(3)</a> is implemented internally on most systems as <a href="http://www.tin.org/bin/man.cgi?section=2&amp;topic=alarm">alarm(2)</a> and <a href="http://www.tin.org/bin/man.cgi?section=2&amp;topic=sigsuspend">sigsuspend(2)</a>. This means that this is an in-kernel question, not a userspace question. However, we know from <a href="http://www.tin.org/bin/man.cgi?section=3&amp;topic=clock_gettime">clock_gettime(3)</a> that the kernel has multiple internal clocks. CLOCK_MONOTONIC is defined as:</p>
<blockquote>
<p>Clock that cannot be set and represents monotonic time since some unspecified starting point.</p>
</blockquote>
<p>This must be whats used for alarm(), which makes sense.</p>
<p>On a related note:</p>
<p>Those annoying programs that behave very oddly when you change the system time are broken. Theyre using <a href="http://www.tin.org/bin/man.cgi?section=2&amp;topic=gettimeofday">gettimeofday(2)</a> or something that derives from it (i.e. <a href="http://www.tin.org/bin/man.cgi?section=2&amp;topic=time">time(2)</a>) instead of properly calling clock_gettime(CLOCK_MONOTONIC).</p>
<!--# include file="include/bottom.html" -->