以下代码是一个内核patchhtml
#include <linux/init.h> #include <linux/module.h> #include <linux/moduleparam.h> MODULE_LICENSE("Dual BSD/GPL"); static char *who= "world"; static int times = 1; module_param(times,int,S_IRUSR); module_param(who,charp,S_IRUSR); static int hello_init(void) { int i; for(i=0;i<times;i++) printk(KERN_ALERT "(%d) hello, %s!\n",i,who); return 0; } static void hello_exit(void) { printk(KERN_ALERT"Goodbye, %s!\n",who); } module_init(hello_init); module_exit(hello_exit);
编译后,加载该代码用命令linux
insmod hello who="world" times=5
卸载该代码用学习
rmmod hello
TODOcode
学习如何编译
阅读 http://tldp.org/LDP/lkmpg/2.6/html/lkmpg.htmlhtm