hello 模块代码如下:
#include <linux/init.h>
#include <linux/module.h>
MODULE_LICENSE("Dual BSD/GPL");
static int howmany = 1;
static char *whom = "world";
module_param(howmany, int, S_IRUGO);
module_param(whom, charp, S_IRUGO);
static int hello_init(void)
{
int i;
for (i = 0;i < howmany; i++) {
printk(KERN_ALERT "Hello, %s\n", whom);
}
return 0;
}
static void hello_exit(void)
{
printk(KERN_ALERT "Goodbye, cruel world\n");
}
module_init(hello_init);
module_exit(hello_exit);
module_init宏用来指定hello模块加载后内核执行的初始化函数。
module_exit宏用来指定hello模块被卸载时内核执行的清除函数。
module_param指定的参数值可以通过加载模块时给出。