printk is used in kernel programming to print messages into the kernel logs.
The syntax of printk is
The log levels decide the importance of the message being printed, kernel defines 8 log levels in the file printk.h
We can see each log level corresponds to a number and the lower the number higher the importance of the message.
The levels are useful in deciding what should be displayed to the user on the console and what should not be.
Every console has log level called as the the console log level and any message with a log level number lesser than the console log level gets displayed on the console, and other messages which have a log level number higher or equal to the console log level are logged in the kernel log which can be looked into using the command "dmesg".
The console loglevel can be found by looking into the file /proc/sys/kernel/printk
The first number in the output is the console log level, the second is the default log level, third is the minimum log level and fourth is the maximum log level.
Log level 4 corresponds to KERN_WARNING. Thus all the messages with log levels 3,2,1 and 0 will get displayed on the screen as well as logged and the messages with log level 4,5,6,7 only get logged and can be viewed using "dmesg".
The console log level can be changed by writing into the proc entry
Now the console log level is set to 6, which is KERN_INFO.
We can test logging by using the following module
hello.c:
The printk called in the init function uses KERN_WARNING which is log level and lesser than 6 which is the console log level and hence should be seen on the screen.
The printk used in the exit function is KERN_INFO which is log level 6,same as the console log level, and hence should not be visible on the screen.
Note: We can test the operation of the code only by logging into a text mode as none of the messages are displayed on a terminal of GUI.
Makefile:
Compile and insert
We can see the hello world being printed on the screen.
The good bye world message gets logged but is not printed on the screen but can be see in the logs.
Thus using printk and the console log levels we can control the kernel messages visible to the user.
The syntax of printk is
The log levels decide the importance of the message being printed, kernel defines 8 log levels in the file printk.h
We can see each log level corresponds to a number and the lower the number higher the importance of the message.
The levels are useful in deciding what should be displayed to the user on the console and what should not be.
Every console has log level called as the the console log level and any message with a log level number lesser than the console log level gets displayed on the console, and other messages which have a log level number higher or equal to the console log level are logged in the kernel log which can be looked into using the command "dmesg".
The console loglevel can be found by looking into the file /proc/sys/kernel/printk
The first number in the output is the console log level, the second is the default log level, third is the minimum log level and fourth is the maximum log level.
Log level 4 corresponds to KERN_WARNING. Thus all the messages with log levels 3,2,1 and 0 will get displayed on the screen as well as logged and the messages with log level 4,5,6,7 only get logged and can be viewed using "dmesg".
The console log level can be changed by writing into the proc entry
Now the console log level is set to 6, which is KERN_INFO.
We can test logging by using the following module
hello.c:
The printk called in the init function uses KERN_WARNING which is log level and lesser than 6 which is the console log level and hence should be seen on the screen.
The printk used in the exit function is KERN_INFO which is log level 6,same as the console log level, and hence should not be visible on the screen.
Note: We can test the operation of the code only by logging into a text mode as none of the messages are displayed on a terminal of GUI.
Makefile:
Compile and insert
We can see the hello world being printed on the screen.
The good bye world message gets logged but is not printed on the screen but can be see in the logs.
Thus using printk and the console log levels we can control the kernel messages visible to the user.
Most valuable article. Really I got more knowledge from this article. Thanks.
ReplyDeletePlacement Training in Chennai
placement classes
Placement Training institutes
Placement Training in Adyar
soft skills training in chennai
soft skill training courses in chennai
clinical sas training in chennai
SAS Training in Chennai
Good Post and its informative one. Thank you for sharing this good article, it was so good to read and very useful to update my skill as updated one.
ReplyDeleteLinux Training in Electronic City
Thanks for sharing such a great blog Keep posting..
ReplyDeleteLinux Training in Delhi
Linux Training Course in Delhi
I want to know more about American eagle credit card login
ReplyDeleteI have seen your blog and really amazing information put in this. If anyone needs Website Designing and Digital Marketing Services in India, visit Ogen Infosystem in Delhi to get a creative and responsive website.
ReplyDeleteBest Website Designing Company in India
iso registration in delhi
ReplyDeleteiso certification in faridabad
ISO 9001 Certification in Noida
website designing services
SEO Service Consultant
iso certification in noida
ReplyDeleteiso certification in delhi
ce certification in delhi
iso 14001 certification in delhi
iso 22000 certification in delhi
iso consultants in noida
we have provide the best fridge repair service.
ReplyDeletefridge repair in faridabad
Videocon Fridge Repair in Faridabad
Whirlpool Fridge Repair in Faridabad
Hitachi Fridge Repair In Faridabad
Washing Machine Repair in Noida
godrej washing machine repair in noida
whirlpool Washing Machine Repair in Noida
IFB washing Machine Repair in Noida
LG Washing Machine Repair in Noida
we have provide the best ppc service.
ReplyDeleteppc company in gurgaon
website designing company in Gurgaon
PPC company in Noida
seo company in gurgaon
PPC company in Mumbai
PPC company in Chandigarh
Digital Marketing Company
Rice Bags Manufacturers
ReplyDeletePouch Manufacturers
wall putty bag manufacturers
fertilizer bag manufacturers
Lyrics with music
Thanks for posting. Linux Tutorial
ReplyDeleteThanks for Fantasctic blog and its to much informatic which i never think ..Keep writing and grwoing your self
ReplyDeleteadd name in birth certificate
name add in birth certificate
birth certificate in delhi
download birth certificate online
birth certificate in ghaziabad
birth certificate in gurgaon
birth certificate in noida
how to get birth certificate in delhi
birth certificate online
how to download birth certificate
Great Article. Thank you for sharing! Really an awesome post for every one.
ReplyDeleteIEEE Final Year projects Project Centers in Chennai are consistently sought after. Final Year Students Projects take a shot at them to improve their aptitudes, while specialists like the enjoyment in interfering with innovation. For experts, it's an alternate ball game through and through. Smaller than expected IEEE Final Year project centers ground for all fragments of CSE & IT engineers hoping to assemble. Final Year Project Domains for IT It gives you tips and rules that is progressively critical to consider while choosing any final year project point.
Spring Framework has already made serious inroads as an integrated technology stack for building user-facing applications. Spring Framework Corporate TRaining the authors explore the idea of using Java in Big Data platforms.
Specifically, Spring Framework provides various tasks are geared around preparing data for further analysis and visualization. Spring Training in Chennai
Male escorts in Delhi
ReplyDeletephp online training in chennai
ReplyDeletephp programming center in chennai
php class in chennnai
php certification course
php developer training institution chennai
php training in chennnai
php mysql course in chennai
php institute in chennnai
php course in chennnai
php training with placement in chennnai
php developer course
appium online training
ReplyDeleteappium training centres in chennai
best appium training institute in chennnai
apppium course
mobile appium in chennnai
mobile training in chennnai
appium training institute in chennnai
The next time I read a blog, Hopefully it does not disappoint me just as much as this one. After all, Yes, it was my choice to read, however I really believed you'd have something interesting to talk about. All I hear is a bunch of crying about something you could possibly fix if you were not too busy seeking attention.
ReplyDeleteTech info
I’m impressed, I must say. Rarely do I come across a blog that’s both equally educative and amusing, and let me tell you, you have hit the nail on the head. The problem is something which not enough folks are speaking intelligently about. website Now i'm very happy that I stumbled across this in my hunt for something regarding this.
ReplyDeleteMicrowaves travel in a straight line, just like other forms of electromagnetic radiation. When obstacles get in the way, they block microwave communications, leading to system failure.microwave networking
ReplyDeleteNice post Nursing Dissertation Help
ReplyDelete