helloworld 带参的写法,让我们显示循环10次

#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);

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值