md.jamal
md.jamal

Reputation: 4567

Debug messages not being printed on the console

I am trying to enable printing the debug messages on the console.

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

MODULE_LICENSE("GPL");
static int test_hello_init(void)
{
    printk(KERN_INFO"%s: In init\n", __func__);
    return 0;
}

static void test_hello_exit(void)
{
    printk(KERN_INFO"%s: In exit\n", __func__);
}

module_init(test_hello_init);
module_exit(test_hello_exit);

To get the Info messages on the console, i executed the following command: dmesg -n7

 cat /proc/sys/kernel/printk
7   4   1   7

When I load the module using insmod, i don't get any message on the terminal, while it is available when I type dmesg. What mistake i am making here.

Upvotes: 1

Views: 1495

Answers (1)

Robert Baldyga
Robert Baldyga

Reputation: 182

Messages from kernel are not printed on terminal (unless it's specified as console= in kernel cmdline). They are appended to kernel log, which exists in kernel. It's accessible to user space programs via device file /dev/kmsg. This file is read by dmesg command in order to print kernel log content on terminal.

Upvotes: 1

Related Questions