printk(9)
π printk(9) β Kernel API Manual π
okay bestie, so the header situation: this is printk(9) from the Kernel API Manual, and no I'm not copying that line verbatim, we're folding it in cute-style, you're welcome π«Ά
β¨ NAME β¨
printk β print a kernel message π¬
πΈ SYNOPSIS πΈ
printk (fmt , ... );
π ARGUMENTS π
fmtβ the format string, the blueprint of your message, the main character of the call β¨...β variable arguments, aka the vibes you feed into the format string, as many as you need π
π¦ DESCRIPTION π¦
This is printk. That's it, that's the whole intro, iconic behavior honestly. It can be called from any context β any. context. We want it to work, and we mean it fr fr π₯
If printk indexing is enabled, _printk is called from printk_index_wrap. Otherwise, printk is simply #defined to _printk. That's the whole routing situation, no cap.
Now the juicy part: we try to grab the console_lock. If we succeed, it's easy β we log the output and call the console drivers. Slay, done, no drama π
But if we fail to get the semaphore? Not me panicking β we just place the output into the log buffer and return. The current holder of the console_sem will notice the new output in console_unlock, and will send it to the consoles before releasing the lock. Teamwork, bestie π«Ά
β οΈ lowkey important caveat: one effect of this deferred printing is that code which callsprintkand then changesconsole_loglevelmay break. This is becauseconsole_loglevelis inspected when the actual printing occurs. So likeβ¦ the timing is giving delayed-reaction and your loglevel change might arrive too late π
See also: printf(3)
See the vsnprintf documentation for format string extensions over C99. yes really, go read it, it's the lore π
π SEE ALSO π
Kernel file ./include/linux/printk.h, printk_cpu_sync_get_irqsave(9), printk_cpu_sync_put_irqrestore(9), pr_fmt(9), pr_emerg(9), pr_alert(9), pr_crit(9), pr_err(9), pr_warn(9), pr_notice(9), pr_info(9), pr_cont(9), pr_devel(9), pr_debug(9), print_hex_dump_bytes(9) β a whole friend group of logging besties, go say hi π
and that's the whole page!! π sign-off time: this little beauty lives under ./include/linux, dated October 2026, and it's printk(9) forever and always β bye bestie, go log something π
π¦ where this page comes from
- nixpkgs unstable: linux-manual 7.3.1
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms