内核编程入门

转载:https://www.cnblogs.com/bitor/p/9608725.html

1、hello world

//必要的头文件

#include<linux/module.h>

#include<linux/kernel.h>

#include<linux/init.h>

//模块许可证声明(必须)

MODULE_LICENSE("Dual BSD/GPL");

//模块加载函数(必须)

staticinthello_init(void){

    printk(KERN_ALERT "Hello World enter/n");

    return 0;

}

//模块卸载函数(必须)

staticvoidhello_exit(void){

    printk(KERN_ALERT "Hello World exit/n");

}

//模块的注册

module_init(hello_init);

module_exit(hello_exit);

//声明模块的作者(可选)

MODULE_AUTHOR("XXX");

//声明模块的描述(可选)

MODULE_DESCRIPTION("This is a simple example!/n");

//声明模块的别名(可选)

MODULE_ALIAS("A simplest example");

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容