Is sleep(3) effected by time changes?
This commit is contained in:
20
2006-02-13-is-sleep-effected-by-time-changes.html
Normal file
20
2006-02-13-is-sleep-effected-by-time-changes.html
Normal 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>It’s an interesting question. I tried it; it isn’t. Here’s my guess at an explanation:</p>
|
||||||
|
|
||||||
|
<p><a href="http://www.tin.org/bin/man.cgi?section=3&topic=sleep">sleep(3)</a> is implemented internally on most systems as <a href="http://www.tin.org/bin/man.cgi?section=2&topic=alarm">alarm(2)</a> and <a href="http://www.tin.org/bin/man.cgi?section=2&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&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 what’s 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. They’re using <a href="http://www.tin.org/bin/man.cgi?section=2&topic=gettimeofday">gettimeofday(2)</a> or something that derives from it (i.e. <a href="http://www.tin.org/bin/man.cgi?section=2&topic=time">time(2)</a>) instead of properly calling clock_gettime(CLOCK_MONOTONIC).</p>
|
||||||
|
|
||||||
|
<!--# include file="include/bottom.html" -->
|
||||||
@@ -40,6 +40,7 @@
|
|||||||
<li>2009-Sep-11: <a href="2009-09-11-confusing-bind-with-cnames.html">Confusing BIND with CNAMEs</a></li>
|
<li>2009-Sep-11: <a href="2009-09-11-confusing-bind-with-cnames.html">Confusing BIND with CNAMEs</a></li>
|
||||||
<li>2009-Feb-19: <a href="2019-02-19-the-odd-case-of-my-mugging.html">The odd case of my mugging</a></li>
|
<li>2009-Feb-19: <a href="2019-02-19-the-odd-case-of-my-mugging.html">The odd case of my mugging</a></li>
|
||||||
<li>2009-Feb-03: <a href="2009-02-03-5-packet-tcp-connection.html">5-packet TCP connection?</a></li>
|
<li>2009-Feb-03: <a href="2009-02-03-5-packet-tcp-connection.html">5-packet TCP connection?</a></li>
|
||||||
|
<li>2006-Feb-13: <a href="2006-02-13-is-sleep-effected-by-time-changes.html">Is sleep(3) effected by time changes?</a></li>
|
||||||
<li>2006-Feb-09: <a href="2006-02-09-convert-all-tables-to-innodb.html">Convert all tables to InnoDB</a></li>
|
<li>2006-Feb-09: <a href="2006-02-09-convert-all-tables-to-innodb.html">Convert all tables to InnoDB</a></li>
|
||||||
<li>2006-Feb-09: <a href="2006-02-09-php-perl-ruby-exploit.html">PHP/PERL/Ruby exploit</a></li>
|
<li>2006-Feb-09: <a href="2006-02-09-php-perl-ruby-exploit.html">PHP/PERL/Ruby exploit</a></li>
|
||||||
<li>2006-Feb-07: <a href="2006-02-07-why-is-my-ssh-x-window-forwarding-broken.html">Why is my SSH X Window forwarding broken?</a></li>
|
<li>2006-Feb-07: <a href="2006-02-07-why-is-my-ssh-x-window-forwarding-broken.html">Why is my SSH X Window forwarding broken?</a></li>
|
||||||
|
|||||||
18
markdown/2006-02-13-is-sleep-effected-by-time-changes.md
Normal file
18
markdown/2006-02-13-is-sleep-effected-by-time-changes.md
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
<!--# set var="title" value="Is sleep(3) effected by time changes?" -->
|
||||||
|
<!--# set var="date" value="February 13, 2006" -->
|
||||||
|
|
||||||
|
<!--# include file="include/top.html" -->
|
||||||
|
|
||||||
|
It’s an interesting question. I tried it; it isn’t. Here’s my guess at an explanation:
|
||||||
|
|
||||||
|
[sleep(3)](http://www.tin.org/bin/man.cgi?section=3&topic=sleep) is implemented internally on most systems as [alarm(2)](http://www.tin.org/bin/man.cgi?section=2&topic=alarm) and [sigsuspend(2)](http://www.tin.org/bin/man.cgi?section=2&topic=sigsuspend). This means that this is an in-kernel question, not a userspace question. However, we know from [clock\_gettime(3)](http://www.tin.org/bin/man.cgi?section=3&topic=clock_gettime) 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)](http://www.tin.org/bin/man.cgi?section=2&topic=gettimeofday) or something that derives from it (i.e. [time(2)](http://www.tin.org/bin/man.cgi?section=2&topic=time)) instead of properly calling clock\_gettime(CLOCK\_MONOTONIC).
|
||||||
|
|
||||||
|
<!--# include file="include/bottom.html" -->
|
||||||
@@ -39,6 +39,7 @@
|
|||||||
1. 2009-Sep-11: [Confusing BIND with CNAMEs](2009-09-11-confusing-bind-with-cnames.html)
|
1. 2009-Sep-11: [Confusing BIND with CNAMEs](2009-09-11-confusing-bind-with-cnames.html)
|
||||||
1. 2009-Feb-19: [The odd case of my mugging](2019-02-19-the-odd-case-of-my-mugging.html)
|
1. 2009-Feb-19: [The odd case of my mugging](2019-02-19-the-odd-case-of-my-mugging.html)
|
||||||
1. 2009-Feb-03: [5-packet TCP connection?](2009-02-03-5-packet-tcp-connection.html)
|
1. 2009-Feb-03: [5-packet TCP connection?](2009-02-03-5-packet-tcp-connection.html)
|
||||||
|
1. 2006-Feb-13: [Is sleep(3) effected by time changes?](2006-02-13-is-sleep-effected-by-time-changes.html)
|
||||||
1. 2006-Feb-09: [Convert all tables to InnoDB](2006-02-09-convert-all-tables-to-innodb.html)
|
1. 2006-Feb-09: [Convert all tables to InnoDB](2006-02-09-convert-all-tables-to-innodb.html)
|
||||||
1. 2006-Feb-09: [PHP/PERL/Ruby exploit](2006-02-09-php-perl-ruby-exploit.html)
|
1. 2006-Feb-09: [PHP/PERL/Ruby exploit](2006-02-09-php-perl-ruby-exploit.html)
|
||||||
1. 2006-Feb-07: [Why is my SSH X Window forwarding broken?](2006-02-07-why-is-my-ssh-x-window-forwarding-broken.html)
|
1. 2006-Feb-07: [Why is my SSH X Window forwarding broken?](2006-02-07-why-is-my-ssh-x-window-forwarding-broken.html)
|
||||||
|
|||||||
Reference in New Issue
Block a user