Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

dmesg is not showing printk statement

I'm trying to create a proc entry. My init_module function is as below

int init_module()
{
printk(KERN_INFO "proc2:Module Loaded\n");
proc_entry=proc_create_data(proc_name,0644,NULL,&fops,NULL);
if(proc_entry==NULL)
{
    printk(KERN_INFO "proc2:Error registering proc entry");
}
else
{
    printk(KERN_INFO "proc2:Proc Entry Created");
}
return 0;
}

following is cleanup method

void cleanup_module()
{
printk(KERN_INFO "proc2:module unloaded");
remove_proc_entry(proc_name,proc_entry);
}

rest of program include variable definition and callback functions.

when i compile this program it compiles well. when i use insmod it doesn't reply me prompt. lsmod lists my module and shows used by one (don't know what). dmesg shows none of the above printk messages.

can you tell me what's wrong here?

like image 327
Kumar Gaurav Avatar asked Sep 04 '13 06:09

Kumar Gaurav


People also ask

Where can I find printk messages?

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 printk works in Linux?

printk is a C function from the Linux kernel interface that prints messages to the kernel log. It accepts a string parameter called the format string, which specifies a method for rendering an arbitrary number of varied data type parameter(s) into a string. The string is then printed to the kernel log.

Is printk buffered?

Printk is implemented by using a ring buffer in the kernel with a size of __LOG_BUF_LEN bytes where __LOG_BUF_LEN equals (1 << CONFIG_LOG_BUF_SHIFT) (see kernel/printk. c for details).

How do I set the kernel log level?

The console log level can also be changed by the klogd program, or by writing the specified level to the /proc/sys/kernel/printk file. The kernel log levels are: 0 (KERN_EMERG) The system is unusable.


1 Answers

Try echo "7" > /proc/sys/kernel/printk to enable all console log levels.

The numbers are corresponding to below:

#define KERN_EMERG "<0>" /* system is unusable*/
#define KERN_ALERT "<1>" /* action must be taken immediately*/
#define KERN_CRIT "<2>" /* critical conditions*/
#define KERN_ERR "<3>" /* error conditions*/
#define KERN_WARNING "<4>" /* warning conditions*/
#define KERN_NOTICE "<5>" /* normal but significant condition*/
#define KERN_INFO "<6>" /* informational*/
#define KERN_DEBUG "<7>" /* debug-level messages*/

The default number is 4, which allows console to show messages only at least in KERN_WARNING. That's why you cannot see log in KERN_INFO level.

like image 111
Wayne Avatar answered Sep 23 '22 05:09

Wayne