hello.c 571 B

12345678910111213141516171819202122232425262728293031
  1. /*
  2. Hello world module.
  3. dmesg -c
  4. insmod hello.ko
  5. dmesg -c | grep 'hello init'
  6. rmmod hello.ko
  7. dmesg -c | grep 'hello exit'
  8. */
  9. #include <linux/module.h>
  10. #include <linux/kernel.h>
  11. static int myinit(void)
  12. {
  13. pr_info("hello init\n");
  14. /* 0 for success, any negative value means failure,
  15. * E* consts if you want to specify failure cause.
  16. * https://www.linux.com/learn/kernel-newbie-corner-loadable-kernel-modules-coming-and-going */
  17. return 0;
  18. }
  19. static void myexit(void)
  20. {
  21. pr_info("hello exit\n");
  22. }
  23. module_init(myinit)
  24. module_exit(myexit)
  25. MODULE_LICENSE("GPL");