Thursday, May 8, 2025

Printk

Kernel cannot access the c lib for printf and has its own functionally equivalent version called printk. Printk writes to a ring buffer, a memory buffer that wrap around. Com and dmesg read and display the content in the ring buffer.  Redhat writes the messages in the ring buffer to /var/log/messages. 

The standard message for printk is to prefix a severity level (alias to a number) to aid filtering. The default (or if not specified) is 4 which equivalent to warning. 

A set of pr_* macros (eg pr_emerg) embeds the printk call make it more handy to emit kernel messages. Pr_debug willl emit the message only if Debug is defined or go nothing. 

No comments: