Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to print a message in one single line in Linux kernel

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]);  

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?

like image 817
jijijijiji Avatar asked Mar 30 '15 03:03

jijijijiji


People also ask

What is printk in Linux kernel?

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.

How do I enable debug prints in Linux kernel?

To activate debug messages for core code and built-in modules during the boot process, even before userspace and debugfs exists, use dyndbg="QUERY" , module.

How do I set the kernel log level?

The console loglevel can be also set via a kernel command-line parameter if you want to use a different value than one specify by CONFIG_CONSOLE_LOGLEVEL_DEFAULT. In that case only messages with a higher priority than KERN_WARNING (means < 4, KERN_EMERG to KERN_ERR ) will be displayed on the console.


1 Answers

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");
like image 164
CL. Avatar answered Sep 19 '22 17:09

CL.