Linux设备驱动程序代码 第2章 建立和运行模块
第2章 建立和运行模块2.2. Hello World 模块2.2.1 代码
//hello.c,Makefile同上//运行:insmod hello howmany=10 whom="Mom" #include <linux/init.h>#include <linux/module.h>#include <linux/moduleparam.h>MODULE_LICENSE("Dual BSD/GPL");static char *whom = "world";static int howmany = 1;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 "(%d) Hello, %s\n", i, whom);return 0;}static void hello_exit(void){printk(KERN_ALERT "Goodbye, cruel world\n");}module_init(hello_init);module_exit(hello_exit);