<s>
printk	B-Application
is	O
a	O
C	B-Language
function	O
from	O
the	O
Linux	B-Application
kernel	I-Application
interface	I-Application
that	O
prints	O
messages	O
to	O
the	O
kernel	O
log	O
.	O
</s>
<s>
It	O
accepts	O
a	O
string	O
parameter	O
called	O
the	O
format	B-Language
string	I-Language
,	O
which	O
specifies	O
a	O
method	O
for	O
rendering	O
an	O
arbitrary	O
number	O
of	O
varied	O
data	O
type	O
parameter(s )	O
into	O
a	O
string	O
.	O
</s>
<s>
It	O
provides	O
a	O
printf-like	O
abstraction	O
and	O
its	O
parsing	O
of	O
the	O
format	B-Language
string	I-Language
and	O
arguments	O
behave	O
similarly	O
to	O
printf	B-Language
.	O
</s>
<s>
The	O
printk	B-Application
function	O
prototype	O
is	O
:	O
</s>
<s>
C	B-Language
standard	I-Language
library	I-Language
and	O
its	O
printf	B-Language
function	O
is	O
unavailable	O
in	O
kernel	O
mode	O
,	O
hence	O
the	O
need	O
for	O
printk	B-Application
.	O
</s>
<s>
The	O
function	O
printk	B-Application
is	O
based	O
on	O
printf	B-Language
,	O
but	O
cannot	O
always	O
be	O
used	O
in	O
the	O
same	O
way	O
that	O
printf	B-Language
is	O
used	O
.	O
</s>
<s>
printk	B-Application
allows	O
a	O
caller	O
to	O
specify	O
the	O
type	O
and	O
importance	O
of	O
the	O
message	O
being	O
sent	O
.	O
</s>
<s>
The	O
log	O
level	O
is	O
specified	O
by	O
prepending	O
(	O
using	O
C	B-Language
's	O
string	O
literal	O
concatenation	O
)	O
a	O
string	O
describing	O
the	O
log	O
level	O
to	O
the	O
start	O
of	O
the	O
message	O
to	O
be	O
produced	O
.	O
</s>
<s>
The	O
string	O
specifying	O
the	O
log	O
level	O
consists	O
of	O
the	O
ASCII	B-Protocol
start	O
of	O
header	O
character	O
followed	O
by	O
a	O
digit	O
describing	O
the	O
log	O
level	O
or	O
the	O
character	O
'	O
c	B-Language
 '	O
to	O
indicate	O
the	O
message	O
is	O
a	O
continuation	O
of	O
the	O
previous	O
message	O
.	O
</s>
<s>
Which	O
log	O
levels	O
are	O
printed	O
is	O
configured	O
using	O
the	O
sysctl	B-Application
file	O
/proc/sys/kernel/printk	O
.	O
</s>
<s>
The	O
%p	O
format	O
specifier	O
(	O
used	O
for	O
printing	O
pointers	O
in	O
printf	B-Language
)	O
is	O
extended	O
to	O
add	O
additional	O
formatting	O
modes	O
,	O
for	O
example	O
,	O
requesting	O
to	O
print	O
a	O
struct	O
sockaddr	O
*	O
using	O
%pISpc	O
would	O
print	O
an	O
IPv4/v6	O
address	O
and	O
port	O
in	O
a	O
human-friendly	O
format	O
(	O
e.g.	O
</s>
<s>
While	O
printf	B-Language
support	O
output	O
of	O
floating	O
point	O
numbers	O
,	O
printk	B-Application
does	O
not	O
,	O
since	O
the	O
Linux	O
kernel	O
does	O
not	O
use	O
floating	O
point	O
numbers	O
within	O
the	O
kernel	O
.	O
</s>
<s>
The	O
function	O
tries	O
to	O
lock	O
the	O
semaphore	B-Operating_System
controlling	O
access	O
to	O
the	O
system	O
console	O
.	O
</s>
<s>
If	O
it	O
is	O
not	O
possible	O
to	O
acquire	O
the	O
semaphore	B-Operating_System
the	O
output	O
is	O
placed	O
into	O
the	O
log	O
buffer	O
,	O
and	O
the	O
current	O
holder	O
of	O
the	O
console	O
semaphore	B-Operating_System
will	O
notice	O
the	O
new	O
output	O
when	O
they	O
release	O
the	O
console	O
semaphore	B-Operating_System
and	O
will	O
send	O
the	O
buffered	O
output	O
to	O
the	O
console	O
before	O
releasing	O
the	O
semaphore	B-Operating_System
.	O
</s>
<s>
One	O
effect	O
of	O
this	O
deferred	O
printing	O
is	O
that	O
code	O
which	O
calls	O
printk	B-Application
and	O
then	O
changes	O
the	O
log	O
levels	O
to	O
be	O
printed	O
may	O
break	O
.	O
</s>
<s>
The	O
function	O
printk	B-Application
can	O
be	O
called	O
from	O
anywhere	O
in	O
the	O
kernel	O
except	O
during	O
the	O
very	O
early	O
stages	O
of	O
the	O
kernel	O
boot	O
process	O
,	O
when	O
the	O
system	O
console	O
is	O
not	O
initialised	O
.	O
</s>
<s>
The	O
alternative	O
function	O
early_printk	O
is	O
implemented	O
on	O
some	O
architectures	O
and	O
is	O
used	O
identically	O
to	O
printk	B-Application
during	O
the	O
early	O
stages	O
of	O
the	O
boot	O
process	O
.	O
</s>
