c - 以错误的顺序调用内核模块 Init 和 Exit 函数

标签 c linux module kernel kernel-module

我正在制作一个非常简单的 hello world 内核模块并出现一些疯狂的行为。这一直有效,直到我升级到内核 3.3.8,现在它...嗯,它在退出时调用 init 函数,在初始化时调用 exit 函数。我已经确定我的名字是正确的

// Needed for module definitions
#include <linux/module.h>
// Needed for initilization modules
#include <linux/init.h>

// Must declare some license
MODULE_LICENSE("Dual BSD/GPL");

// Function to be called on insmod
// Returns 0 on success
static int __init mymod_init(void)
{
        // Prints kernel alert.  Check /var/log/syslog
        printk(KERN_ALERT "Module was loaded, this is the printk.");

        return 0;
}

// Function to be called on rmmod
static void __exit mymod_exit(void)
{
        // Prints kernel alert.  Check /var/log/syslog
        printk(KERN_ALERT "Module was unloaded, this is the printk");
}

// Register these functions
module_init(mymod_init);
module_exit(mymod_exit);

示例输出:

root@cop4610:/home/cop4610/Downloads/linux-3.3.8/mymodule# insmod mymodule.ko root@cop4610:/home/cop4610/Downloads/linux-3.3.8/mymodule# tail /var/log/syslog Oct 12 10:08:20 cop4610 kernel: [ 633.567832] Module was unloaded, this is the printk

以下是现场直播的视频: http://www.youtube.com/watch?v=8aJNSpCd7as&feature=youtu.be

最佳答案

它需要换行!!!!!!啊!!!

 printk(KERN_ALERT "Module was unloaded, this is the printk\n");

 printk(KERN_ALERT "Module was loaded, this is the printk\n");

看起来它并没有真正乱序,它只是出现了,因为第一个直到第二个发出时才出现,因为缓冲区没有被刷新。

关于c - 以错误的顺序调用内核模块 Init 和 Exit 函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12861230/

相关文章:

mysql - iptables 导致外部站点连接 mysql 时出现问题

excel - 在模块中调用 UserForm_Initialize()

python - 没有名为 pyglet 的模块

c++ - Axis/C MIME/DIME 和 MTOM 入门

c++ - C/C++ 如何将宏参数扩展为引号之间的文本

c - 什么是 C 中的目标文件?

c - 链接 apache 库

c - 为具有多个接口(interface)的设备设置 MTU

c - 在 linux 上删除终端输出

magento - 在 magento 自定义模块的后端添加多个选项卡和表单,就像客户后端位置一样