Chapter2 - Building and Running: The Hello World Module
The Hello World Module The hello world is a very simple kernel module. We will try to explore the same in this blog. I am assuming on your distribution (Debian, Ubuntu, Fedora, CentOS..etc) you have installed all the dependency packages, Kernel Source, and header files of the running kernel. The sample hello.c kernel module can #include <linux/module.h> #include <linux/init.h> MODULE_LICENSE("Dual BSD/GPL"); MODULE_AUTHOR("NARESH BHAT"); static int __init hello_init(void) { printk(KERN_ALERT "Hello World!\n"); return 0; } static void __exit hello_exit(void) { printk(KERN_ALERT "Good Bye, Cruel World!\n"); } module_init(hello_init); module_exit(hello_exit); When a module is loaded hello_init will be called and after unloading the kernel hello_exit function will be called by running kernel. These are defined by module_init and module_exit kernel macros. Hence the module compile...