一个空的内核模块

#include <linux/init.h>
#include <linux/module.h>

/**
 * This function is called when the module is first loaded.
 */    
static int __init hello_kernel_init(void)
{
    printk("Hello, World!\n");
    return 0;
}

/**
 * This function is called when is called if and when the module is unloaded.
 */
static void __exit hello_kernel_exit(void)
{
    printk("Goodbye, cruel world...\n");
}

/* The names of the init/exit functions are arbitrary, and they are bound using the following macro definitions */
module_init(hello_kernel_init);
module_exit(hello_kernel_exit);

为了编写 Linux 设备驱动程序(字符设备,块设备等),有必要创建一个具有入口和出口点的内核模块。

内核模块本身什么都不做; 没有有意义的方式与用户空间进行通信。使用入口点可以创建新的字符设备,例如,然后用于与用户空间通信。