mirror of https://github.com/mkerrisk/man-pages
select.2, select_tut.2: Consolidate info on usleep() emulation in one place
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
This commit is contained in:
parent
a63fef4359
commit
bd89babbed
|
@ -287,14 +287,6 @@ struct timespec {
|
|||
.EE
|
||||
.in
|
||||
.PP
|
||||
Some code calls
|
||||
.BR select ()
|
||||
with all three sets empty,
|
||||
.I nfds
|
||||
zero, and a non-NULL
|
||||
.I timeout
|
||||
as a fairly portable way to sleep with subsecond precision.
|
||||
.PP
|
||||
On Linux,
|
||||
.BR select ()
|
||||
modifies
|
||||
|
@ -448,6 +440,18 @@ when
|
|||
.B _GNU_SOURCE
|
||||
is defined.
|
||||
.\"
|
||||
.SS Emulating usleep(3)
|
||||
.PP
|
||||
Before the advent of
|
||||
.BR usleep (3),
|
||||
some code employed a call to
|
||||
.BR select ()
|
||||
with all three sets empty,
|
||||
.I nfds
|
||||
zero, and a non-NULL
|
||||
.I timeout
|
||||
as a fairly portable way to sleep with subsecond precision.
|
||||
.\"
|
||||
.SS Correspondence between select() and poll() notifications
|
||||
Within the Linux kernel source,
|
||||
.\" fs/select.c
|
||||
|
|
|
@ -463,24 +463,6 @@ then the sets must be reinitialized before each call.
|
|||
.\" Having no file descriptors set is a useful
|
||||
.\" way to sleep the process with subsecond precision by using the timeout.
|
||||
.\" (See further on.)
|
||||
.SS Usleep emulation
|
||||
On systems that do not have a
|
||||
.BR usleep (3)
|
||||
function, you can call
|
||||
.BR select ()
|
||||
with a finite timeout and no file descriptors as
|
||||
follows:
|
||||
.PP
|
||||
.in +4n
|
||||
.EX
|
||||
struct timeval tv;
|
||||
tv.tv_sec = 0;
|
||||
tv.tv_usec = 200000; /* 0.2 seconds */
|
||||
select(0, NULL, NULL, NULL, &tv);
|
||||
.EE
|
||||
.in
|
||||
.PP
|
||||
This is guaranteed to work only on UNIX systems, however.
|
||||
.SH RETURN VALUE
|
||||
On success,
|
||||
.BR select ()
|
||||
|
|
Loading…
Reference in New Issue