Kernel modules must have at least two functions: a "start" (initialization) function called init_module() which is called when the module is insmoded into the kernel, and an "end" (cleanup) function called cleanup_module() which is called just before it is rmmoded. Actually, things have changed starting with kernel 2.3.13. You can now use whatever name you like for the start and end functions of a module. In fact, the new method is the preferred method.
#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 new_method_init(void)
{
printk (KERN_INFO "Hello, world 2\n");
return 0;
}
static void exit new_method_exit(void)
{
printk (KERN_INFO "Goodbye, world 2\n");
}
module_init(new_method_init);
module_exit(new_method_exit);