gjain
gjain

Reputation: 4518

Why are kernel log messages in the syslog file (or those redirected to terminal) exactly one 'message' behind?

I wrote a simple hello-world module on Ubuntu 10.04 machine. When loading and unloading the module, printk should log messages from the following hello_world and bye_world functions.

static int hello_world()
{
        printk(KERN_INFO "Hello, beautiful world");
        return 0;
}

static void bye_world()
{
        printk(KERN_INFO "Good-bye kernel uncle");
}

module_init(hello_world);
module_exit(bye_world);

However, when actually inserting and removing the hello.ko module, I see that the message printed on the terminal (I redirected it to the current terminal) is exactly one message behind.

# rmmod hello.ko
# Jul  8 16:34:02 panchavati kernel: [64599.954113] Hello, beautiful world

# insmod hello.ko
# Jul  8 16:34:57 panchavati kernel: [65456.367422] Good-bye kernel uncle

From dmesg output, I can see the next message entry (corresponding to insmod) has been already logged, just that it is not being printed yet.

chanakya@panchavati:~$ dmesg | tail -2
[65456.367422] Good-bye kernel uncle
[65511.198299] Hello, beautiful world

The entry [65511.198299] is there in the kernel log, but only the previous entry [65456.367422] Good-bye kernel uncle was printed. Why is it so?

I earlier thought that '-' specifier used in /etc/syslog.conf might have to do something with this (it prevents synchronization after every write), but removing it didn't work either.

Upvotes: 1

Views: 1737

Answers (2)

dns
dns

Reputation: 81

Try ending your strings with a newline ("\n").

Upvotes: 1

superdesk
superdesk

Reputation: 1172

Have you tried using tailf (or tail -f)? It will print out the messages as they arrive. For example:

    tailf /var/log/messages

Upvotes: 2

Related Questions