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 <mtk.manpages@gmail.com>
This commit is contained in:
Michael Kerrisk 2017-02-27 17:10:48 +01:00
parent 91bf33ff1f
commit 1186d4c363
1 changed files with 19 additions and 0 deletions

View File

@ -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.,