打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
最简单的内核模块编程
代码:
/* hello.c */
#include <linux/module.h>
#include <linux/kernel.h>    /* Optional, to include printk() prototype */
#include <linux/init.h>        /* Optional, to include module_init() macros */

static int __init hello_init(void)
{
    printk("Hello, how are you?/n");

    /* A non 0 return means init_module failed; module can't be loaded. */
    return 0;
}

static void __exit hello_exit(void)
{
    printk("I'm fine. Goodbye!/n");
}

module_init(hello_init);
module_exit(hello_exit);


编译方法:
1. 准备好一个配置编译好的内核代码树
2. 把 hello.c 放置在一个单独的目录,并在这个目录中编写一个Makefile:
obj-m := hello.o
3. 编译命令:make -C <内核代码树目录> M=`pwd`

运行方法:
1. 当前运行的内核和要执行的模块是同一版本,root 权限。
2. insmod ./hello.ko
3. 卸载:rmmod hello
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
linux设备驱动归纳总结(二):模块的相关基础概念
小白学Linux之内核模块编程-tiger
Linux设备驱动Hello World程序介绍
2.6内核模块的编写框架和编译方法
内核驱动进阶
iTOP-RK3399开发板驱动模块传数组
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服