一個空的核心模組

#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 裝置驅動程式(字元裝置,塊裝置等),有必要建立一個具有入口和出口點的核心模組。

核心模組本身什麼都不做; 沒有有意義的方式與使用者空間進行通訊。使用入口點可以建立新的字元裝置,例如,然後用於與使用者空間通訊。