Linux 驱动学习_20180704

/*
Notifier chains are of four types:
    Atomic notifier chains : run in interrupt/atomic context.
    Blocking notifier chains : run in process context.
    Raw notifier chains : 
    SRCU notifier chains :
    
*/
struct notifier_block
{
    notifier_fn_t notifier_call;
    struct notifier_block __rcu* next;
    int priority;
};

内核子系统之间的信息传递;

子系统通常只在boot或者加载module时注册notifier block,即修改notification chain

#include <linux/init.h>
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/notifier.h>
#include <linux/reboot.h>

MODULE_LICENSE("Dual BSD/GPL");

static int myreboot(struct notifier_block *self, unsigned long event, void *data)
{
        printk(KERN_ALERT "Just a test! Event code: %li! System reboot now...", event);
        return NOTIFY_OK;
}
static struct notifier_block myreboot_notifier = {
        .notifier_call = myreboot,
};
static int myreboot_init(void)
{
        register_reboot_notifier(&myreboot_notifier);
        return 0;
}
static void myreboot_exit(void)
{
        unregister_reboot_notifier(&myreboot_notifier);
}
module_init(myreboot_init);
module_exit(myreboot_exit);

下面给出一个简单的使用notification chain的例子。

该模块向reboot_notifier_list 注册了一个函数myreboot,该函数在系统reboot时会简单地打印一些信息;



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值