From 0fa0ed4f6309526ffaf8bfc3cae00f89ab0d6804 Mon Sep 17 00:00:00 2001 From: Ian Gulliver Date: Sun, 21 Apr 2019 17:23:22 +0000 Subject: [PATCH] Is sleep(3) effected by time changes? --- ...-13-is-sleep-effected-by-time-changes.html | 20 +++++++++++++++++++ index.html | 1 + ...02-13-is-sleep-effected-by-time-changes.md | 18 +++++++++++++++++ markdown/index.md | 1 + 4 files changed, 40 insertions(+) create mode 100644 2006-02-13-is-sleep-effected-by-time-changes.html create mode 100644 markdown/2006-02-13-is-sleep-effected-by-time-changes.md diff --git a/2006-02-13-is-sleep-effected-by-time-changes.html b/2006-02-13-is-sleep-effected-by-time-changes.html new file mode 100644 index 0000000..c6fd5c1 --- /dev/null +++ b/2006-02-13-is-sleep-effected-by-time-changes.html @@ -0,0 +1,20 @@ + + + + + +

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).

+ + diff --git a/index.html b/index.html index de22ec3..a0268e8 100644 --- a/index.html +++ b/index.html @@ -40,6 +40,7 @@
  • 2009-Sep-11: Confusing BIND with CNAMEs
  • 2009-Feb-19: The odd case of my mugging
  • 2009-Feb-03: 5-packet TCP connection?
  • +
  • 2006-Feb-13: Is sleep(3) effected by time changes?
  • 2006-Feb-09: Convert all tables to InnoDB
  • 2006-Feb-09: PHP/PERL/Ruby exploit
  • 2006-Feb-07: Why is my SSH X Window forwarding broken?
  • diff --git a/markdown/2006-02-13-is-sleep-effected-by-time-changes.md b/markdown/2006-02-13-is-sleep-effected-by-time-changes.md new file mode 100644 index 0000000..46dbce6 --- /dev/null +++ b/markdown/2006-02-13-is-sleep-effected-by-time-changes.md @@ -0,0 +1,18 @@ + + + + + +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). + + diff --git a/markdown/index.md b/markdown/index.md index 67d11e4..d72381e 100644 --- a/markdown/index.md +++ b/markdown/index.md @@ -39,6 +39,7 @@ 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-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: [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)