wfc0003 wfc0003 - 1 year ago 63
Linux Question

Kernel Module: No printk messages showing. Is init function being called?

I have a simple module, written as follows:

#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/init.h>


static int __init hellomod_init(void)
printk(KERN_DEBUG, "Hello, world!\n");
return 0;

static void __exit hellomod_exit(void)
printk(KERN_DEBUG, "Goodbye, world!");



$ cat /proc/sys/kernel/printk
7 7 7 7

so that any level messages should output.

The module loads and this can be verified with lsmod, however no output is produced when loading or unloading the module and checking dmesg.

I have tried replacing "KERN_DEBUG" with lower levels and still no output, so I don't think the log level is the issue.

How else can I verify the init function is called? If it is not being called, what is my error?

I am running and compiling against kernel version 4.6.1-2 on Arch Linux.

e: oops

Answer Source

There shouldn't be a comma after KERN_DEBUG. So it should look something like this:

static int __init hellomod_init(void)
    printk(KERN_DEBUG "Hello, world!\n");
    return 0;