module_param与MODULE_PARM_DESC

#include <linux/init.h>
#include <linux/module.h>

static int watchdog = 5000;
/* watdog默认值是5000, 但是可以通过 insmod hello.ko watchdog=1000设置非默认值 */
module_param(watchdog, int, 0644);

/* 对模块的参数进行描述 */
MODULE_PARM_DESC(watchdog, "transmit timeout in million seconds.");

static int hello_init(void)
{
        printk(KERN_INFO " Hello World enter\n");
        printk(KERN_INFO " watchdog->[%d]\n", watchdog);
        return 0;
}

static void hello_exit(void)
{
        printk(KERN_INFO " Hello World exit\n ");
}

module_init(hello_init);
module_exit(hello_exit);

MODULE_AUTHOR("Barry Song <[email protected]>");
MODULE_LICENSE("Dual BSD/GPL");
MODULE_DESCRIPTION("A simple Hello World Module");
MODULE_ALIAS("a simplest module");

查看模块输出:
tail -f /var/log/message:
Sep 13 17:22:54 bogon kernel:  <6> Hello World enter
Sep 13 17:22:54 bogon kernel:  watchdog->[1000]

查看模块信息:
[root@bogon hello]# rmmod hello.ko
[root@bogon hello]# insmod hello.ko  watchdog=1000
[root@bogon hello]# modinfo  hello.ko
filename:       hello.ko
alias:          a simplest module
description:    A simple Hello World Module
license:        Dual BSD/GPL
author:         Barry Song <[email protected]>
srcversion:     CA550DAF62F17A9B23FFCD6
depends:       
vermagic:       2.6.18-194.el5 SMP mod_unload 686 REGPARM 4KSTACKS gcc-4.1
parm:           watchdog:transmit timeout in million seconds. (int)

你可能感兴趣的:(module_param与MODULE_PARM_DESC)