這篇文章給大家介紹Linux內(nèi)核代碼,傳參數(shù),內(nèi)容非常詳細(xì),感興趣的小伙伴們可以參考借鑒,希望對(duì)大家能有所幫助。
一、源代碼
1.1 temp_main.c
#include#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #define LOG_INFO(fmt,args...) printk(KERN_INFO fmt, ##args) static int int_var = 0; static const char *str_var = "default"; static int int_arr[6]; int narr; module_param(int_var, int, 0644); MODULE_PARM_DESC(int_var, "A integer variable"); module_param(str_var, charp, 0644); MODULE_PARM_DESC(str_var, "A string variable"); module_param_array(int_arr, int, &narr, 0644); MODULE_PARM_DESC(int_arr, "A integer array"); static int init_marker(void) { int i; LOG_INFO("int_var: %d.\n", int_var); LOG_INFO("str_var: %s.\n", str_var); for (i=0; i 1.2 Makefile
obj-m := temp.o temp-objs := temp_main.o KERNELDIR = /lib/modules/$(shell uname -r)/build PWD := $(shell pwd) default: $(MAKE) -C $(KERNELDIR) M=$(PWD) modules clean: $(MAKE) -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean install: cp temp.ko ../二、運(yùn)行
insmod temp.ko int_var=123 str_var=helloworld int_arr=100,200,300
三、運(yùn)行結(jié)果
關(guān)于Linux內(nèi)核代碼,傳參數(shù)就分享到這里了,希望以上內(nèi)容可以對(duì)大家有一定的幫助,可以學(xué)到更多知識(shí)。如果覺(jué)得文章不錯(cuò),可以把它分享出去讓更多的人看到。
當(dāng)前名稱:如何給Linux內(nèi)核代碼傳參數(shù)-創(chuàng)新互聯(lián)
本文網(wǎng)址:http://weahome.cn/article/dpgiie.html