加入收藏 | 设为首页 | 会员中心 | 我要投稿 网站开发网_马鞍山站长网 (https://www.0555zz.com/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长百科 > 正文

Handling of asynchronous events---reference

发布时间:2021-01-29 08:45:36 所属栏目:站长百科 来源:网络整理
导读:副标题#e# http://www.win.tue.nl/~aeb/linux/lk/lk-12.html 12.?Handling of asynchronous events One wants to be notified of various events,like data that has become available,files that have changed,and signals that have been raised. FreeBSD

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);
    }

}

(编辑:网站开发网_马鞍山站长网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!