如何在Linux内核的一行中打印一条消息 [英] How to print a message in one single line in Linux kernel
本文介绍了如何在Linux内核的一行中打印一条消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在内核中制作一个简单的enque/deque程序.我想在内核中打印消息,这就是我得到的:
I am making a simple enque/deque program in kernel. I want to print message in kernel, and this is what I got:
[18594.595747] Enqueue 3
[18594.595748] queue :
[18594.595751] 2
[18594.595751] 1
[18594.595752] 3
但是我想不使用换行符来打印它:
But I want to print this without newline:
[8594.595747] Enqueue 3
[18594.595748] queue : 2 1 3
这是我的代码的一部分:
This is a part of my code:
printk(KERN_ALERT "Enqueue %d \n queue : ", a);
rear++;
for(i = front; i<rear; i++)
printk(KERN_ALERT "%d ", queue_test[i]);
简而言之,我想在内核中一行打印一条消息.但是,如果我使用printk,它将自动更改行.如何在一行中打印一条消息?
In short, I want to print in kernel a message in one line. But if I use printk, it changes line automatically. How do I print a message in one line?
推荐答案
要防止新行开始,请使用KERN_CONT
:
To prevent a new line from being started, use KERN_CONT
:
printk(KERN_ALERT "self destruction commences in ");
printk(KERN_CONT "%d", time_remaining);
printk(KERN_CONT " minutes\n");
这篇关于如何在Linux内核的一行中打印一条消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文