LDD3 帶有引數的模組

2021-05-28 12:42:24 字數 977 閱讀 8290

#include

#include

#include

static char *who= "who";

static int time= 1;

module_param(time, int, s_irugo);

module_param(who, charp, s_irugo);

static int hello_init(void)

{int i=0;

for (i=0; i

測試結果:

[root@localhost module_with_arg]#

[root@localhost module_with_arg]# insmod book.ko who=ericjiang time=2

[root@localhost module_with_arg]#

message from syslogd@ at wed sep 28 02:34:06 2011 ...

localhost kernel: hello,world::::2:ericjiang

[root@localhost module_with_arg]# rmmod book.ko

[root@localhost module_with_arg]#

message from syslogd@ at wed sep 28 02:42:06 2011 ...

localhost kernel: hello,world::::2:ericjiang

message from syslogd@ at wed sep 28 02:42:06 2011 ...

localhost kernel: goobye,world

[root@localhost module_with_arg]#

因為重複的訊息只會顯示一次,所以上面的現象是正常的。

原始碼為:

module_with_arg.tar.gz

LDD3學習筆記 模組的編譯

新手上路,ldd3學習之旅開始,以下內容純屬筆記,若有錯誤,望見諒!1.什麼是 模組 可以在系統執行時加入到核心中的 故 模組包括但不限於裝置驅動程式。2.如何寫乙個模組?1 c檔案 2 實現module init,module exit3.ldd3中makefile編寫規則 照搬 ifneq ke...

LDD3速記 per CPU變數

當建立乙個per cpu變數時,系統的每個處理器都會有改變量的特有副本 對per cpu的訪問無需鎖定 可以儲存在快取記憶體 eg.網路子系統 的計數器 include define per cpu type,name 編譯期間建立per cpu變數 declare per cpu type,nam...

ldd3學習之二 構造和執行模組

設定一套核心原始碼樹,比如 usr src linux 2.6.x,參考 eg uname r 2.6.32 27 generic wget pub linux kernel v2.6 linux 2.6.32.27.tar.gz 直接用發行版的核心原始碼包,比如 lib modules shell...