Handling of asynchronous events---reference
副标题[/!--empirenews.page--]
http://www.win.tue.nl/~aeb/linux/lk/lk-12.html 12.?Handling of asynchronous eventsOne wants to be notified of various events,like data that has become available,files that have changed,and signals that have been raised. FreeBSD has the nice?API. Let us discuss the Unix/Linux situation. It is easy to wait for a single event. Usually one does a (blocking)? Many mechanisms exist to wait for any of a set of events,or just to test whether anything interesting happened. 12.1?O_NONBLOCKIf the? A nonblocking open is useful (i) in order to obtain a file descriptor for subsequent use when no I/O is planned,e.g. for? O_NOACCESSAn obscure Linux feature is that one can open a file with the O_NOACCESS flag (defined as 3,where O_RDONLY is 0,O_WRONLY is 1 and O_RDWR is 2). In order to open a file with this mode,one needs both read and write permission. This had the same purpose: announce that no reading or writing was going to be done,and only a file descriptor for ioctl use was needed. (Used in LILO,fdformat,and a few similar utilities.) People would love to have this facility also for directories,so that one could do a? 12.2?selectThe? int select(int nfds,fd_set *restrict readfds,fd_set *restrict writefds,fd_set *restrict errorfds,struct timeval *restrict timeout); It allows one to specify three sets of file descriptors (as bit masks) and a timeout. The call returns when the timeout expires or when one of the file descriptors in There are two select system calls. The old one uses a parameter block,the new one uses five parameters. Otherwise they are equivalent. 12.3?pselectThe? int gotsignal = 0; Now if one wants to wait for either a signal or some event on a file descriptor,then testing the flag and if it is not set calling? The call? int pselect(int nfds,const struct timespec *restrict timeout,const sigset_t *restrict sigmask); with a sixth parameter? sigset_t origmask; as an atomic action. Now one can block the signals of interest until the call of? This function uses a struct timespec (with nanoseconds) instead of a struct timeval (with microseconds),and does not update its value on return. The self-pipe trickBefore the introduction of? The system call(编辑:ASP站长) 【免责声明】本站内容转载自互联网,其相关言论仅代表作者个人观点绝非权威,不代表本站立场。如您发现内容存在版权问题,请提交相关链接至邮箱:bqsm@foxmail.com,我们将及时予以处理。 |
-
无相关信息