Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

printk() doesn't print in /var/log/messages

My OS Ubuntu 12.04. I wrote this Kernel Module and i use insmod and rmmod command but there isn't anything in /var/log messages. how can i fix this problem?

/*  
*  hello-1.c - The simplest kernel module.
*/
#include <linux/module.h>   /* Needed by all modules */
#include <linux/kernel.h>   /* Needed for KERN_INFO */

int init_module(void)
{
   printk(KERN_INFO "Hello world 1.\n");

    /* 
    * A non 0 return means init_module failed; module can't be loaded. 
    */
    return 0;
 }

 void cleanup_module(void)
 {
   printk(KERN_INFO "Goodbye world 1.\n");
 }
like image 934
amiref Avatar asked May 09 '13 15:05

amiref


People also ask

Can printk() messages specify log levels?

printk () messages can specify a log level. the format string, while largely compatible with C99, doesn’t follow the exact same specification. It has some extensions and a few limitations (no %n or floating point conversion specifiers). See How to get printk format specifiers right.

Where are the printk() messages printed?

All printk () messages are printed to the kernel log buffer, which is a ring buffer exported to userspace through /dev/kmsg. The usual way to read it is using ``dmesg``.

How do I read a printk message in Linux?

All printk () messages are printed to the kernel log buffer, which is a ring buffer exported to userspace through /dev/kmsg. The usual way to read it is using dmesg. where KERN_INFO is the log level (note that it’s concatenated to the format string, the log level is not a separate argument). The available log levels are:

What is printk() in the Linux kernel?

printk () is one of the most widely known functions in the Linux kernel. It’s the standard tool we have for printing messages and usually the most basic way of tracing and debugging. If you’re familiar with printf (3) you can tell printk () is based on it, although it has some functional differences: printk () messages can specify a log level.


1 Answers

Check whether syslog daemon process is running, since this is the process which copies printk messages from kernel ring/log message buffer to /var/log/messages if I am correct. printk messages can be seen using dmesg utility/command or messages will be in /var/log/messages. If correct loglevel is set then printk messages will be displayed on the console right away, no need to use dmesg or no need to check in /var/log/messages. printk debug messages can also be part of /var/log/syslog.

like image 175
Gautham Kantharaju Avatar answered Oct 14 '22 16:10

Gautham Kantharaju