1

I just read that Linux kernel modules can't print to the screen i.e. printf won't work. Does it have something to do with interrupt handling or why is that the case?

I have a memory studying some C and assembly which you couldn't use printf with and that was because interrupts were off.

6

In the kernel, printf doesn’t work because it’s not implemented! You use printk instead (or early_printk in very early code, before the console is set up). printk is coded very carefully so that’s it’s safe to call from anywhere, in any circumstances (in particular, it doesn’t need to allocate memory). It implements pretty much the same API as printf, with the addition of a log level to indicate the importance of the message being printed, and format specifiers which are useful in the kernel.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.