我是靠谱客的博主 粗心菠萝,这篇文章主要介绍Linux信号异步通知应用和驱动编程,现在分享给大家,希望可以做个参考。

一:设备驱动层

 struct x_dev{

    ...

   struct fasync_struct *async;

};

/*fasync函数*/

static int x_fasync(int fd, struct file *filp, int mode)

{

    struct x_dev *dev = filp->private_data;

    return fasync_helper(fd, filp, mode, &dev->async);

}

 

/*添加到 file_operations*/

static const struct file_operations x_fops = {
     ...
    .fasync      =     x_fasync,
    ....
};

 

/*读写函数中释放信号*/

 struct x_dev *dev = filp->private_data;

if(dev->async)

    kill_fasync(&dev->async, SIGIO, POLL_IN(或者POLL_OUT));

 

/*release函数中删除*/

  x_fasync(-1, filp, 0 );

 

二:用户空间

static void signal_handler(int signum)

{

}

 

 void main(void)

{

    int fd, flag;

    fd = open("/dev/xx", O_RDWR, S_IRUSR | S_IWUSR);

    signal(SIGIO, signal_handler);

    fcntl(fd, F_SETOWN, getpid());

    flag = fcntl(fd, F_GETFL);

    fcntl(fd, F_SETFL, flag | FASYNC);

    while(1);

}

 

 

 

最后

以上就是粗心菠萝最近收集整理的关于Linux信号异步通知应用和驱动编程的全部内容,更多相关Linux信号异步通知应用和驱动编程内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(43)

评论列表共有 0 条评论

立即
投稿
返回
顶部