1<html><head><meta http-equiv="Content-Type" content="text/html; charset=ANSI_X3.4-1968"><title>printk</title><meta name="generator" content="DocBook XSL Stylesheets V1.78.1"><link rel="home" href="index.html" title="Linux Device Drivers"><link rel="up" href="ch01s09.html" title="Kernel utility functions"><link rel="prev" href="API-container-of.html" title="container_of"><link rel="next" href="API-console-lock.html" title="console_lock"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center"><span class="phrase">printk</span></th></tr><tr><td width="20%" align="left"><a accesskey="p" href="API-container-of.html">Prev</a> </td><th width="60%" align="center">Kernel utility functions</th><td width="20%" align="right"> <a accesskey="n" href="API-console-lock.html">Next</a></td></tr></table><hr></div><div class="refentry"><a name="API-printk"></a><div class="titlepage"></div><div class="refnamediv"><h2>Name</h2><p>printk — 2 print a kernel message 3 </p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><div class="funcsynopsis"><table border="0" class="funcprototype-table" summary="Function synopsis" style="cellspacing: 0; cellpadding: 0;"><tr><td><code class="funcdef">__visible int <b class="fsfunc">printk </b>(</code></td><td>const char * <var class="pdparam">fmt</var>, </td></tr><tr><td> </td><td> <var class="pdparam">...</var><code>)</code>;</td></tr></table><div class="funcprototype-spacer"> </div></div></div><div class="refsect1"><a name="idp1108423332"></a><h2>Arguments</h2><div class="variablelist"><dl class="variablelist"><dt><span class="term"><em class="parameter"><code>fmt</code></em></span></dt><dd><p> 4 format string 5 </p></dd><dt><span class="term"><em class="parameter"><code>...</code></em></span></dt><dd><p> 6 variable arguments 7 </p></dd></dl></div></div><div class="refsect1"><a name="idp1108425932"></a><h2>Description</h2><p> 8 This is <code class="function">printk</code>. It can be called from any context. We want it to work. 9 </p><p> 10 11 We try to grab the console_lock. If we succeed, it's easy - we log the 12 output and call the console drivers. If we fail to get the semaphore, we 13 place the output into the log buffer and return. The current holder of 14 the console_sem will notice the new output in <code class="function">console_unlock</code>; and will 15 send it to the consoles before releasing the lock. 16 </p><p> 17 18 One effect of this deferred printing is that code which calls <code class="function">printk</code> and 19 then changes console_loglevel may break. This is because console_loglevel 20 is inspected when the actual printing occurs. 21</p></div><div class="refsect1"><a name="idp1108428492"></a><h2>See also</h2><p> 22 printf(3) 23 </p><p> 24 25 See the <code class="function">vsnprintf</code> documentation for format string extensions over C99. 26</p></div></div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="API-container-of.html">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="ch01s09.html">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="API-console-lock.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top"><span class="phrase">container_of</span> </td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top"> <span class="phrase">console_lock</span></td></tr></table></div></body></html> 27