helloworld驱动-创新互联

简单驱动——helloworld驱动

创新互联公司专注为客户提供全方位的互联网综合服务,包含不限于网站设计制作、成都网站建设、雅安网络推广、微信平台小程序开发、雅安网络营销、雅安企业策划、雅安品牌公关、搜索引擎seo、人物专访、企业宣传片、企业代运营等,从售前售中售后,我们都将竭诚为您服务,您的肯定,是我们大的嘉奖;创新互联公司为所有大学生创业者提供雅安建站搭建服务,24小时服务热线:13518219792,官方网址:www.cdcxhl.com

驱动分为四个部分
头文件
驱动模块的入口和出口
声明信息
功能实现

第一步,包含头文件

#include//包含宏定义的头文件
#include//包含初始化加载模块的头文件
第二部,驱动模块的入口和出口

module_init(hello_init);//模块入口
module_exit(hello_exit);//模块出口
第三步,声明模块拥有开源许可证

MODULE_LICENSE(“GPL”);
第四部,功能实现

static int hello_init(void)
{
printk(“hello world\n”);
return 0;
}
static int hello_exit(void)
{
printk(“bye bye\n”);
return 0;
}
内核模块加载的时候打印hello world,内核模块卸载的时候打印bye bye

注意:内核打印函数不能用printf,因为内核没有办法使用C语言库

整体代码如下:

#include//包含宏定义的头文件
#include//包含初始化加载模块的头文件
#include
static int hello_init(void)
{
printk(“hello world\n”);
return 0;
}

static void hello_exit(void)
{
printk(“bye bye\n”);
return 0;
}

module_init(hello_init);//模块入口
module_exit(hello_exit);//模块出口

MODULE_LICENSE(“GPL”);

你是否还在寻找稳定的海外服务器提供商?创新互联www.cdcxhl.cn海外机房具备T级流量清洗系统配攻击溯源,准确流量调度确保服务器高可用性,企业级服务器适合批量采购,新人活动首月15元起,快前往官网查看详情吧


当前名称:helloworld驱动-创新互联
文章链接:http://myzitong.com/article/dejjpi.html