# Printing on console from a kernel module



## GroupInode (Feb 10, 2012)

Is it possible for me to print on the console from a kernel module using uprintf?


----------



## monkeyboy (Feb 10, 2012)

What do you mean by "console"? I believe printf() prints a message to the console, i.e. on a PC, the terminal associated with the system video card, and uprintf() prints a message to a user terminal, i.e. the controlling TTY of the process associated with current kernel action. There are other variants, essentially frontends to the routine kvprintf(). See the file subr_prf.c.


----------



## GroupInode (Feb 10, 2012)

monkeyboy said:
			
		

> what do you mean by "console" ?
> I believe printf() prints a message to the console, i.e. on a PC, the terminal associated with the system video card, and uprintf() prints a message to a user terminal, i.e. the controlling tty of the process associated with current kernel action. There are other variants, essentially frontends to the routine kvprintf(). See the file subr_prf.c .



I basically want something that will work like printf but for a kernel module. Because I think printf won't work in kernel module.


----------



## monkeyboy (Feb 10, 2012)

GroupInode said:
			
		

> I basically want something that will work like printf but for a kernel module. Because I think printf won't work in kernel module.


really? Did you try it? I don't see why it wouldn't and plenty of loadable kernel modules use printf(). Both printf() and uprintf() call the same underlying kvprintf() routine, so it should all work the same...

Hopefully you already understand that the printf() in the kernel is not the same routine as the printf(3S) in the stdio.h library. And you should NOT #include <stdio.h>. And you cannot manipulate filedescriptors, stdin, etc in the kernel. Also the kernel printf() implements/understands a very restrictive subset of formatting specs compared with printf(3S). Look in subr_prf.c to see what you are allowed to do.


----------

