printk(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

πŸ’– 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 calls printk and then changes console_loglevel may break. This is because console_loglevel is 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