From 1186d4c36365e5575e45e0596323008813dfc3ec Mon Sep 17 00:00:00 2001 From: Michael Kerrisk Date: Mon, 27 Feb 2017 17:10:48 +0100 Subject: [PATCH] nanosleep.2: Describe "creeping sleep" problem nanosleep() has a problem if used in a program that catches signals and those signals are delivered at a very high rate. Describe the problem, and note that clock_nanosleep(2) provides a solution. Signed-off-by: Michael Kerrisk --- man2/nanosleep.2 | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/man2/nanosleep.2 b/man2/nanosleep.2 index 0845d260b..06ef85096 100644 --- a/man2/nanosleep.2 +++ b/man2/nanosleep.2 @@ -194,6 +194,25 @@ or This special extension was removed in kernel 2.5.39, and is thus not available in Linux 2.6.0 and later kernels. .SH BUGS +If a program that catches signals and uses +.BR nanosleep () +receives signals at a very high rate, +then scheduling delays and rounding errors in the kernel's +calculation of the sleep interval and the returned +.IR remain +value mean that the +.IR remain +value may steadily +.IR increase +on successive restarts of the +.BR nanosleep () +call. +To avoid such problems, use +.BR clock_nanosleep (2) +with the +.BR TIMER_ABSTIME +flag to sleep to an absolute deadline. + In Linux 2.4, if .BR nanosleep () is stopped by a signal (e.g.,