我注意到内核模块中有一些奇怪的行为。当我运行以下代码(使用等待队列)时。在 finish_wait() 之后,printk() 不会出现在内核日志中。 第 5 行也只打印一次。知道发生了什么事吗?
DEFINE_WAIT(wait);
DECLARE_WAIT_QUEUE_HEAD(wait_q);
flags |= O_NONBLOCK;
while (( err = kthread->sock->ops->accept(kthread->sock, kthread->sock_send, flags) ) < 0){
printk("%s: before prepare_to_wait err = -%d\n", __func__,err);
prepare_to_wait(&wait_q, &wait, TASK_INTERRUPTIBLE);
if(kthread_should_stop()){
printk("%s: killing thread\n", __func__);
msleep(1000);
finish_wait(&wait_q, &wait);
goto close_and_out;
}
schedule();
}
finish_wait(&wait_q, &wait);
printk("after finish wait: This doesn't show up in kernel logs...\n");
最佳答案
将优先级添加到日志消息中:
喜欢:printk(KERN_ALERT 你的信息); 此外,KERN_ALERT 和您的消息之间不会有“逗号” 如果不是 KERN_ALERT,请尝试使用不同的级别。
Rgds, 软软的
关于linux-kernel - linux 内核等待队列 - printk 未显示在消息日志中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10687603/