c – 为什么我的hello world驱动模块没有打印任何东西?
发布时间:2020-12-16 05:06:00 所属栏目:百科 来源:网络整理
导读:我对内核模块编程很新,现在我正在尝试运行最基本的hello world模块程序,但是我无法获得任何输出. 我已经编写了Linux设备驱动程序第3版中引入的hello world程序,并从this website和this one获得了一些帮助. 你好? #include linux/module.h#include linux/kern
我对内核模块编程很新,现在我正在尝试运行最基本的hello world模块程序,但是我无法获得任何输出.
我已经编写了Linux设备驱动程序第3版中引入的hello world程序,并从this website和this one获得了一些帮助. 你好? #include <linux/module.h> #include <linux/kernel.h> MODULE_LICENSE("GPL"); static int hello_init(void){ printk("<1>Hello,world!n"); return 0; } static void hello_exit(void){ printk(KERN_ALERT "Goodbye,world..n"); } module_init(hello_init); module_exit(hello_exit); 该文件位于/ home / volkan / drive目录中.连同c文件,我有我的Makefile Makefile文件 obj-m += hello.o 从终端,我执行此命令来编译模块: sudo make -C /lib/modules/3.8.0-19-generic/build M=/home/volkan/drive/ modules 导致: make: Entering directory `/usr/src/linux-headers-3.8.0-19-generic' CC [M] /home/volkan/drive/hello.o Building modules,stage 2. MODPOST 1 modules CC /home/volkan/drive/hello.mod.o LD [M] /home/volkan/drive/hello.ko make: Leaving directory `/usr/src/linux-headers-3.8.0-19-generic' 我认为到目前为止,没有任何问题.现在,我插入我的模块,然后删除: volkan@Varaquilex ~/drive $sudo insmod ./hello.ko volkan@Varaquilex ~/drive $sudo rmmod hello volkan@Varaquilex ~/drive $ 没有输出.我也没什么经验,所以解释性答案非常受欢迎.难道我做错了什么?为什么我看不到任何输出? 解决方法
内核消息记录在/ var / log中的kern.log文件中.根据您的系统,它也可能是dmesg.所以你必须相应地.
使用命令cat /var/log/kern.log Dec 9 18:51:10 Varaquilex kernel: [ 2818.079572] <1>Hello,world! Dec 9 18:55:02 Varaquilex kernel: [ 3050.256134] Goodbye,world.. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |