Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
639 views
in Technique[技术] by (71.8m points)

linux kernel - 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
");
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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...