#include<linux/init.h>
#include<linux/module.h>
#include<linux/moduleparam.h>//模块传参的头文件
MODULE_LICENSE("Dual BSD/GPL");
static int num = 10;
static char * whom = "haha ";
module_param(num ,int ,S_IRUGO);//带参数的第一个是参数 第二个是参数类型 ,第三个是访问许可值(任何人可以读取该参数),S_IRUGO | S_IWUSR 表示root用户修改该参数
module_param(whom,charp,S_IRUGO);
/*if we can't find the massage try the cmd : tail -2 /var/log/message
*it has some level ,you can write the marco like KERN_EMERG or the num like "<0>"
* */
static int __init hello_init(void)
{
while(num--)
printk("<0>" "hello world %s\n",whom);
return 0;
}
static void __exit hello_exit(void)
{
printk(KERN_EMERG "goodbye world\n");
}
module_init(hello_init);
#include<linux/module.h>
#include<linux/moduleparam.h>//模块传参的头文件
MODULE_LICENSE("Dual BSD/GPL");
static int num = 10;
static char * whom = "haha ";
module_param(num ,int ,S_IRUGO);//带参数的第一个是参数 第二个是参数类型 ,第三个是访问许可值(任何人可以读取该参数),S_IRUGO | S_IWUSR 表示root用户修改该参数
module_param(whom,charp,S_IRUGO);
/*if we can't find the massage try the cmd : tail -2 /var/log/message
*it has some level ,you can write the marco like KERN_EMERG or the num like "<0>"
* */
static int __init hello_init(void)
{
while(num--)
printk("<0>" "hello world %s\n",whom);
return 0;
}
static void __exit hello_exit(void)
{
printk(KERN_EMERG "goodbye world\n");
}
module_init(hello_init);
module_exit(hello_exit);
makefile:
obj-m:=hello_prarm.o
all:
make -C /lib/module/`uname -r`/build M='pwd' modules
clean:
rm -fr *.ko *.o *.mod.o