why my kernel log is not showing the latest output?

早过忘川 提交于 2019-11-27 07:33:20

问题


I'm coding a simple kernel module, in linux ubuntu 17.04, that takes a string and prints it in the kernel log.

#include<linux/module.h>
#include<linux/init.h>
#include<linux/moduleparam.h>
char* mystring = "hello world";
module_param(mystring ,charp ,S_IRUSR | S_IWUSR);

void display(void){
printk(KERN_ALERT "%s" ,mystring);
}
static int hello(void){
//printk(KERN_ALERT "hello module");
display();
return 0;
} 
static void bye(void){
printk(KERN_ALERT "bye");
}
module_init(hello);
module_exit(bye);

I run command make and then when I run insmod test.ko mystring="blahblahblah", the module will be inserted correctly but when I run dmesg it doesn't show the "blahblahblah". after I run rmmod test.ko and dmseg the expression "blahblahblah" will appear in the terminal. when I run insmod test.ko mystring="blahblahblah" again and then dmesg the "blahblahblah" will be printed. what is the problem exactly? is it my problem or the system?


回答1:


Sometimes printk may defer output (that is, message is stored in the intrenal buffer, but not in kernel log). For avoid such behavior, always add newline (\n) at the end of the string printed:

printk(KERN_ALERT "%s\n" ,mystring);


来源:https://stackoverflow.com/questions/47589197/why-my-kernel-log-is-not-showing-the-latest-output

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!