首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 其他教程 > 其他相关 >

加载驱动时传参数-module_param

2012-09-12 
加载驱动时传参数--module_param加载驱动时传参数的实例:#include linux/init.h#include linux/module.

加载驱动时传参数--module_param

加载驱动时传参数的实例:

#include <linux/init.h>#include <linux/module.h>MODULE_LICENSE("Dual BSD/GPL");static char *string = "param test\n";static int     times = 1; module_param(times, int, S_IRUGO);module_param(string, charp, S_IRUGO);static int hello3_init(void){int i = 0;printk(KERN_ALERT "Hello, World!\n");for(i = 0; i < times; i++){printk("string: %s\n", string);}return 0;}static void hello3_exit(void){printk(KERN_ALERT "Goodbye, cruel world!\n");}module_init(hello3_init);module_exit(hello3_exit);


运行结果:

[root@(none)/]#insmod hello3.ko Hello, World!string: param test[root@(none)/]#rmmod hello3Goodbye, cruel world![root@(none)/]#[root@(none)/]#insmod hello3.ko times=5 string="I AM IN hello3.c\n"Hello, World!string: I AM IN hello3.c\nstring: I AM IN hello3.c\nstring: I AM IN hello3.c\nstring: I AM IN hello3.c\nstring: I AM IN hello3.c\n[root@(none)/]#rmmod hello3Goodbye, cruel world![root@(none)/]#


虽然是入门新手,但坚持下去就会有收获!

加油加油加油!

linux就是黑暗中的一片光明!

热点排行