Wednesday, June 25, 2014

Hello Kernel

In this post we shall be writing a kernel module, which would cause the kernel to print our messages to the kernel log buffer. we shall not be looking deeper into the kernel buffer or the particular commands as that would be stretching this post too long. this is just a jump-start.

The kernel log is available through this command.
sudo dmesg
 
If you look at the messages already printed, they will be more often than not by the drivers , insert and remove a pen drive and run the command again, you will see some messages being printed. I would now advise to clear the kernel log buffer by running the following command.
sudo dmesg -c
 
now if you run the “dmesg” command again, you will see nothing or very minimal data s the old entries have been cleared and fresh entries are being put up.
let’s make the module now, do this task inside a directory you create, I named mine as “test” and the file as test.c. The contents of the file are as follows.

#include <linux/init.h>
#include <linux/module.h>

static int my_init(void){
printk("Hello world");
return 0;
}

static void my_exit(void){
printk("bye-bye");
}

module_init(my_init);
module_exit(my_exit);
 
now in the same directory make a file called Makefile and the contents of the makefile should be these.
obj-m := test.o
 
That’s it… now we run the command to compile our module. The command is as follows
make -C <linux-source-dir>  M=$PWD modules
 
if the compilation is succesful you will have a file named test.ko in the directory. we need to load it by using the insmod command.
sudo insmod test.ko
 
now see the kernel log by
dmesg
 
you would see the two messages “hello world” and “bye-bye”. It is finally done now, you have made the kernel print out a custom message for you.
There would have been many questions on the way but no worries all would be clear with some efforts. The strange make command, the new commands like “insmod” “dmesg” are real simple and can be understood with a simple google search. for the serious minds do read “Linux device drivers by greg kroah hartman” and “Linux kernel development by Robert love” the two very good books that i have always referred to. any more questions? do comment.. more than happy to help.

54 comments:

  1. Great post about internet of things. I like it.

    seo service in nepal

    ReplyDelete
  2. Thanks for providing the great information with us and the you have have explained the topic in clearly and it is easy to understand .
    IoT Training in Hyderabad

    ReplyDelete
  3. This comment has been removed by the author.

    ReplyDelete
  4. Hi, Thanks for sharing this full topic on Internet of things. It is very full to every one. keep it up Internet of things

    ReplyDelete
  5. Thanks for sharing such a great information here. I really appreciate this post and like it very much.and more information

    Please go trough the link : IoT

    training in Hyderabad

    ReplyDelete
  6. Good informative blog. It's very useful site to all. Thanks for the who is posted the good information thanks.
    DevOps Training in Hyderabad

    ReplyDelete
  7. Good Post. I like your blog. Thanks for Sharing good information.
    IoT Training Institute in Noida

    ReplyDelete
  8. Thanks For Sharing The Information The Information Shared Is Very Valuable Please Keep Updating Us Time Just Went On Reading The article Python Online Course

    ReplyDelete
  9. Thank you for sharing such a IoT scope of information. These are the trending technologies that spread all over the world. Internet of Things is also the trending and most required technology that people loves the most.

    ReplyDelete
  10. I enjoyed reading your article about IOT. Please make more interesting topics like this.I'll come back for more��
    Buy tinder accounts

    ReplyDelete
  11. Thanks for your marvelous posting!I really enjoyed reading it. You're a great author.I will be sure to bookmark your blog and will come back very soon.
    Buy bulk aged Gmail accounts

    ReplyDelete
  12. I love visiting sites in my free time. I have visited many sites but did not find any site more efficient than yours Great job for publishing such a beneficial website. Your web log isn’t only useful but it is additionally really creative too. There tend to be not many people who can certainly write not so simple posts that artistically.
    buy google voice number

    ReplyDelete
  13. Thank you arun, For sharing a Fabulous post with a lot of information.
    Buy Google voice pva accounts

    ReplyDelete
  14. Thank You for sharing a great information with us.I have you bookmarked your site to look at the new stuff you post.

    IoT App Development

    ReplyDelete
  15. Great post!!
    Thanks for Sharing a useful content about Internet of things (IoT), Definitely IOT will be the Game Changer of all technology
    IoT Training courses | IoT training

    ReplyDelete
  16. Very nice post. I absolutely love this site. Thanks!
    Buy tinder pva accounts

    ReplyDelete
  17. Such a very useful article. Very interesting to read this article.I would like to thank you for the efforts you had made for writing this awesome article.

    Data Science Institute in Bangalore

    ReplyDelete
  18. I would like to thank you for the efforts you have made in writing this article. I am hoping the same best work from you in the future as well. In fact your creative writing abilities has inspired me to start my own Blog Engine blog now. Really the blogging is spreading its wings rapidly. Your write up is a fine example of it.
    Data Science Course in Bangalore

    ReplyDelete
  19. This comment has been removed by the author.

    ReplyDelete
  20. I just got to this amazing site not long ago. I was actually captured with the piece of resources you have got here. Big thumbs up for making such wonderful blog page!

    Simple Linear Regression

    Correlation vs Covariance


    ReplyDelete
  21. Hey There. I found your blog using msn. This is a very well written article. I’ll be sure to bookmark it and come back to read more of your useful info. Thanks for the post. I’ll definitely return.iot training in delhi

    ReplyDelete
  22. Terrific post thoroughly enjoyed reading the blog and more over found to be the tremendous one. Infact, educating the participants with it's amazing content. Hope you share the similar content consecutively.

    360DigiTMG Data Science Course

    ReplyDelete
  23. Pretty good post blog with excellent information. really enjoyed reading your blog posts thanks for sharing.
    Data Analytics Certification Training 360DigiTMG

    ReplyDelete
  24. I am looking for and I love to post a comment that "The content of your post is awesome" Great work! data science courses

    ReplyDelete
  25. kernel module writing is very hard. So anyone need to write easy way must read this blog. Thank you admin for tis blog buy google voice number

    ReplyDelete
  26. Thanks for sharing the helpful blogpost.pvait

    ReplyDelete
  27. https://www.digitalbrolly.com/digital-marketing-course-in-hyderabad/

    ReplyDelete
  28. Such a very useful article. Very interesting to read this article.I would like to thank you for the efforts you had made for writing this awesome article.
    best data science institute in hyderabad

    ReplyDelete
  29. This article discusses the importance of this blog for business promotion. Promoting a blog is just like promoting any other website and can be difficult to do if you are not sure what needs to be done, but with the right buy google voice number tips and tricks, this doesn't have to be. Hopefully, you find this article on this blog helpful and decide to visit the site below to see just what they are talking about

    ReplyDelete
  30. I have read your excellent post. This is a great job. I have enjoyed reading your post first time. I want to say thanks for this post. Thank you...
    digital marketing courses in hyderabad with placement

    ReplyDelete
  31. To get the most out of IOT, take the option of getting a good night's sleep. So that IOT does not interrupt anyone's sleep, the time when the alert is active can be chosen. These IoTs also provide a variety of alert delivery channels. There are no limits to these items, which range from email to voice recording on one's phone. IoT devices may also remotely monitor a variety of other devices. Visit here https://store.ubibot.com/

    ReplyDelete
  32. Excellent blog, I wish to share your post with my folks circle. It’s really helped me a lot, so keep sharing post like this…

    Data Science Training in Hyderabad

    ReplyDelete
  33. This article discusses
    Buy facebook accounts the importance of this blog for business promotion. Promoting a blog is just like promoting any other website and can be difficult to do if you are not sure what needs to be done, but with the right tips and tricks, this doesn't have to be. Hopefully, you find this article on this blog helpful and decide to visit the site below to see just what they are talking about.
    buy pva gmail accounts

    ReplyDelete
  34. I recently came across your article and have been reading along. I want to express my admiration of your writing skill and ability to make readers read from the beginning to the end. I would like to read newer posts and to share my thoughts with you.
    data scientist course in hyderabad

    ReplyDelete
  35. Thanks for your post. I’ve been thinking about writing a very comparable post over the last couple of weeks, I’ll probably keep it short and sweet and link to this instead if thats cool. Thanks.
    cyber security course malaysia

    ReplyDelete
  36. Your blog provided us with valuable information to work with. Each & every tips of your post are awesome. Thanks a lot for sharing. Keep blogging,
    data scientist training in hyderabad

    ReplyDelete
  37. Nice post! This is a very nice blog that I will definitively come back to more times this year! Thanks for informative post.
    data analytics courses in hyderabad with placements

    ReplyDelete
  38. Learn to use analytics tools and techniques to manage and analyze large sets of data from Data Science training institutes in Bangalore. Learn to take on business challenges and solve problems by uncovering valuable insights from data. Learn from the comprehensively designed curriculum by the industry experts and work on live projects to sharpen your skills.

    Best Data Science Training institute in Bangalore

    ReplyDelete
  39. Learn to use analytics tools and techniques to manage and analyze large sets of data from Data Science training institutes in Bangalore. Learn to take on business challenges and solve problems by uncovering valuable insights from data. Learn from the comprehensively designed curriculum by the industry experts and work on live projects to sharpen your skills.

    Data Science Course in Delhi

    ReplyDelete
  40. Are you looking for a Data Science course that will aid you in your career growth. 360DigiTMG is the right place for you. Enroll now for a better tomorrow.


    Data Scientist Course in Delhi

    ReplyDelete
  41. Unleash your potential and expand your capabilities with the Data Science Certification Course.
    data analytics course in borivali

    ReplyDelete
  42. "If you are also one of them and want to know what the companies demand from the data scientists to do in their organization, you have come to the right place.data science course in kolkata"

    ReplyDelete
  43. This article provides a clear and concise introduction to creating a kernel module in Linux. The step-by-step instructions, along with the provided code snippets, make it accessible even for those new to kernel development. The recommendation of additional resources for deeper learning is a valuable bonus. Great job simplifying a complex topic!
    Data Analytics Courses in Nashik

    ReplyDelete
  44. Hello Blogger,
    This post is a valuable resource for anyone interested in kernel module development in Linux, and the author's willingness to answer questions and provide further assistance is a commendable trait.
    Data Analytics Courses In Dubai

    ReplyDelete
  45. The way you've explained the concept and its real-world applications is both clear and engaging.
    Digital marketing courses in illinois

    ReplyDelete