
檔案 I/O
|
61
select (0, NULL, NULL, NULL, &tv);
當然,Linux 也會為高解析度的休眠機制提供介面。我們將在第 11 章探討這些介面。
pselect()
select()
系統呼叫,是4.2BSD 首先推出的,廣受歡迎,但是 POSIX 卻在 POSIX
1003.1g-2000 以及之後的 POSIX 1003.1-2001 定義自己的解決方案
pselect()
:
#define _XOPEN_SOURCE 600
#include <sys/select.h>
int pselect (int n,
fd_set *readfds,
fd_set *writefds,
fd_set *exceptfds,
const struct timespec *timeout,
const sigset_t *sigmask);
/* 下面如同 select() */
FD_CLR(int fd, fd_set *set);
FD_ISSET(int fd, fd_set *set);
FD_SET(int fd, fd_set *set);
FD_ZERO(fd_set *set);
pselect()
與
select()
之間有三點不同:
•
pselect()
為它的
timeout
參數使用的是
timespec
結構而不是
timeval
結構。
timespec
結構採用的是 seconds(秒)和 nanoseconds(奈秒,即十億分之一秒)的設定值,而
不是 seconds ...