c – 为什么我的hello world驱动模块没有打印任何东西?

前端之家收集整理的这篇文章主要介绍了c – 为什么我的hello world驱动模块没有打印任何东西?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我对内核模块编程很新,现在我正在尝试运行最基本的hello world模块程序,但是我无法获得任何输出.

我已经编写了Linux设备驱动程序第3版中引入的hello world程序,并从this websitethis 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..

猜你在找的C&C++相关文章