|
Just like?pselect?and?ppoll?are versions of?select?and?poll,there is (since 2.6.19) a?epoll_pwait?version of?epoll_wait?that includes a signal mask.
12.6?dnotify
The above was about notification about file descriptors that become ready for I/O. A different type of notification is that about file system events. In 2.4.0-test9 the?dnotify?feature was introduced. Today it is obsoleted by?inotify?(see below). See?Documentation/dnotify.txt?and?fs/dnotify.c.
The idea was that one could register interest in changes in a directory?dir?using?fd = open(dir,O_RDONLY)?followed by?fcntl(fd,F_NOTIFY,...). Notification occurs via delivery of a signal.
/* dnotify demo,basically from Documentation/dnotify.txt */
#define _GNU_SOURCE
#include
#include
#include
#include
static volatile int dir_fd;
/ A very weak interface: we report that something changed,but
the only info is in which directory,but not what the change is. /
static void handler(int sig,siginfo_t si,void data) {
dir_fd = si->si_fd;
}
int main(void) {
struct sigaction act;
int fd;
act.sa_sigaction = handler;
sigemptyset(&act.sa_mask);
act.sa_flags = SA_SIGINFO;
sigaction(SIGRTMIN + 1,&act,NULL);
fd = open(".",O_RDONLY);
fcntl(fd,F_SETSIG,SIGRTMIN + 1);
fcntl(fd,DN_MODIFY|DN_CREATE|DN_DELETE|DN_RENAME|DN_MULTISHOT);
while (1) {
pause();
printf("Got some event on fd=%dn",dir_fd);
}
}
(编辑:网站开发网_马鞍山站长网)
【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!
|