linux内核代码是以模块(module)和子系统(subsys)为单元的层次结构。在写模块代码时我们知道入口函数是module_init()或subsys_initcall(),在linux启动时会被调用,这其中更为详细的前因后果是什么呢,一起来了解一下。
一,linux模块程序示例
下面是一个linux模块的示例程序:
一,linux模块程序示例
下面是一个linux模块的示例程序:
#include <linux/init.h>
#include <linux/module.h>
MODULE_LICENSE("Dual BSD/GPL");
MODULE_AUTHOR("Radia");
static int hello_init()
{
printk(KERN_EMERG "hello module has been mount!\n");
return 0;
}
static void hello_exit()
{
printk(KERN_EMERG "hello module has been remove!\n");
}
module_init(hello_init);
module_exit(hello_exit);