原文地址:https://www.aliyun.com/jiaocheng/147421.html
1.hello.c
3. 编译模块
#sudomake (调用第一个命令default)
这时,在hello.c 所在文件夹就会有 hello.ko,这个就是我们需要的内核模块啦
#sudo make clean
清理编译垃圾,hello.ko 也会清理掉。
4. 插入模块,让其工作。注意必须是root权限
#sudo insmod ./hello.ko
我们用dmesg 就可以看到 产生的内核信息啦,Hello world!
如果没有输出"hello from helloworld",因为如果你在字符终端而不是终端模拟器下运行的话,就会输出,因为在终端模拟器下时会把内核消息输出到日志文件/var/log/kern.log中。
#sudo rmmod ./hello
再用dmesg 可以看到 Bye world!
扩展阅读:
示例一 将开机信息发邮件
dmesg > boot.messages
and mail the boot.messages file to whoever can debug their problem.
[root@new55 ~]# dmesg >boot.messages
[root@new55 ~]# ls -l boot.messages
-rw-r--r-- 1 root root 15838 12-09 12begin_of_the_skype_highlighting 15838 12-0912 免费 end_of_the_skype_highlighting:55boot.messages
[root@new55 ~]# mail -s "Boot Log of Linux Server"public@web3q.net
[root@new55 ~]#
通过管道查找
dmesg | grep world
dmesg | tail
dmesg -a
dmesg -c打印并清除
有问题可联系