首页 > 系统服务 > 详细

linux kernel with param

时间:2014-11-08 23:33:38      阅读:448      评论:0      收藏:0      [点我收藏+]

Linux kernel support pass param to kernel, this params can be assigned at load time by insmod or modprobe.  or later read from /etc/modprobe.conf file.

There are two macro : module_param and module_param_array, 

To declare an param or array param ,use:

module_param(name, type, perm)   module_param_array(name, type, num, perm)

name is the name of your param or array.

type can be : bool ,invbool,charp, int, long, short, uint, ulong, ushort

num is the array num , array param where the values are supplied as a comma-separated list.

perm : S_IRUGO , S_IWUSR and so on .

int num = 0;
static char* array[10] = {NULL};
static int ntime = 0;
static char* pstring = NULL;

module_param_array(array, charp, &num, S_IRUGO);
module_param(ntime, int, S_IRUGO);
module_param(pstring, charp, S_IRUGO);

static int __init init_func(void)
{
        int i = 0;
        printk("string :%s, int :%d\n", pstring, ntime);
        printk("Array\n");
        for(; i < num; ++i)
                printk("%s\n", array[i]);
        return 0;
}

执行:

sudo insmod ./hello.ko array="hello,world" pstring="test" ntime=10

 

linux kernel with param

原文:http://www.cnblogs.com/memoryh/p/4084113.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!