Modules
Kernel modules are collections of code, that can be loaded and unloaded from kernel on demand.
Example hello.c file
#include <linux/module.h> // included for all kernel modules
#include <linux/kernel.h> // included for KERN_INFO
#include <linux/init.h> // included for __init and __exit macros
MODULE_LICENSE("GPL");
MODULE_AUTHOR("Lakshmanan");
MODULE_DESCRIPTION("A Simple Hello World module");
static int __init hello_init(void)
{
printk(KERN_INFO "Hello world!\n");
return 0; // Non-zero return means that the module couldn't be loaded.
}
static void __exit hello_cleanup(void)
{
printk(KERN_INFO "Cleaning up module.\n");
}
module_init(hello_init);
module_exit(hello_cleanup);List all Modules (that are loaded into memory)
$ lsmodCreate new Module
$ sudo insmod <path to the new module.ko>Run it (i think???)
# prints the last output from the module
# dmesg prints everything
$ dmesg | tail -1Info on Module
$ modinfo <path to the new module.ko>Remove Module
$ rmmod <path to the new module.ko>Probe
loads and unloads modules based dependencies