Ref:
1. Coding program : hello2.c
/*
* hello2.c - Demonstrating the module_init() and module_exit() macros.
* This is preferred over using init_module() and cleanup_module().
*/
#include <linux/module.h> /* Needed by all modules */
#include <linux/kernel.h> /* Needed for KERN_INFO */
#include <linux/init.h> /* Needed for the macros */
static int __init hello2_init(void)
{
printk(KERN_INFO "Hello, world - GW2\n");
return 0;
}
static void __exit hello2_exit(void)
{
printk(KERN_INFO "Goodbye, world - GW2\n");
}
module_init(hello2_init);
module_exit(hello2_exit);
2. Makefile
obj-m += hello2.o
all:
make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules
clean:
make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean
3. Fixed try
$make
$insmod hello2.ko
$rmmod hello2
$dmesg