代码部分:
- #include <linux/init.h>
#include <linux/module.h>
#include <linux/moduleparam.h>
static char *who= "who";
static int time= 1;
module_param(time, int, S_IRUGO);
module_param(who, charp, S_IRUGO);- static int hello_init(void)
{
int i=0;
for (i=0; i<time; i++)
printk(KERN_EMERG"HELLO,WORLD::::%s%d\t\n",who,i);
return 0;
} - static int hello_exit(void)
{
printk(KERN_EMERG"GOOBYE,WORLD\t\n");
return 0;
} - module_init(hello_init);
module_exit(hello_exit);
MODULE_LICENSE("Dual BSD/GPL");
EXPORT_SYMBOL(who);
//EXPORT_SYMBOL_GPL(who); - EXPORT_SYMBOL(time);
//EXPORT_SYMBOL_GPL(time);
测试方法及结果:
[root@localhost hello]# insmod hello.ko time=2 who=ericJiang
[root@localhost hello]#
Message from syslogd@ at Mon Aug 13 10:44:01 2012 ...
localhost kernel: HELLO,WORLD::::ericJiang1
Message from syslogd@ at Mon Aug 13 10:44:01 2012 ...
localhost kernel: HELLO,WORLD::::ericJiang0
[root@localhost hello]# rmmod hello.ko
[root@localhost hello]#
Message from syslogd@ at Mon Aug 13 10:48:19 2012 ...
localhost kernel: GOOBYE,WORLD
[root@localhost hello]#