iT邦幫忙

DAY 5
0

Linux kernel模組的開發系列 第 5

執行 kernel module

  • 分享至 

  • twitterImage
  •  

編譯完成了 hello-1.ko 之後,接下來我們就要執行他,而在載入之前先透過 modinfo 命令確認一下他的內容:

[root@Pomelo-14-61 LKMP]# modinfo hello-1.ko
filename:       hello-1.ko
srcversion:     140276773A3090F6F33891F
depends:        
vermagic:       2.6.32-279.22.1.el6.x86_64 SMP mod_unload modversions

接下來使用 insmod 來載入 kernel 中執行:

[root@Pomelo-14-61 LKMP]# insmod hello-1.ko
[root@Pomelo-14-61 LKMP]#

咦,怎麼沒有任何反應? 試試 lsmod 或是 cat /proc/modules 命令來找找他的蹤跡:

[root@Pomelo-14-61 LKMP]# lsmod | grep hello
hello_1                  892  0

[root@Pomelo-14-61 LKMP]# cat /proc/modules | grep hello
hello_1 892 0 - Live 0xffffffffa012f000 (P)

呵,沒錯,hello_1 被載入 kernel 之中了。接著在 /var/log/messages 中確認一下輸出結果:

[root@Pomelo-14-61 LKMP]# tail -1 /var/log/messages
Oct 3 23:14:05 Pomelo-14-61 kernel: Hello world 1.

"Hello world”,耶,成功了。

在試試以 rmmod 命令移除他,同時一併檢查其狀態與輸出結果:

[root@Pomelo-14-61 LKMP]# rmmod hello_1

[root@Pomelo-14-61 LKMP]# lsmod | grep hello

[root@Pomelo-14-61 LKMP]# cat /proc/modules | grep hello

[root@Pomelo-14-61 LKMP]# tail -1 /var/log/messages
Oct  3 23:23:10 Pomelo-14-61 kernel: Goodbye world 1.

上一篇
編譯 Linux kernel module
下一篇
不同的 module init 與 cleanup 做法
系列文
Linux kernel模組的開發30
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言