十年網(wǎng)站開發(fā)經(jīng)驗 + 多家企業(yè)客戶 + 靠譜的建站團隊
量身定制 + 運營維護+專業(yè)推廣+無憂售后,網(wǎng)站問題一站解決
簡單驅(qū)動——helloworld驅(qū)動
驅(qū)動分為四個部分
頭文件
驅(qū)動模塊的入口和出口
聲明信息
功能實現(xiàn)
第一步,包含頭文件
#include
#include
第二部,驅(qū)動模塊的入口和出口
module_init(hello_init);//模塊入口
module_exit(hello_exit);//模塊出口
第三步,聲明模塊擁有開源許可證
MODULE_LICENSE(“GPL”);
第四部,功能實現(xiàn)
static int hello_init(void)
{
printk(“hello world\n”);
return 0;
}
static int hello_exit(void)
{
printk(“bye bye\n”);
return 0;
}
內(nèi)核模塊加載的時候打印hello world,內(nèi)核模塊卸載的時候打印bye bye
注意:內(nèi)核打印函數(shù)不能用printf,因為內(nèi)核沒有辦法使用C語言庫
整體代碼如下:
#include
#include
#include
static int hello_init(void)
{
printk(“hello world\n”);
return 0;
}
static void hello_exit(void)
{
printk(“bye bye\n”);
return 0;
}
module_init(hello_init);//模塊入口
module_exit(hello_exit);//模塊出口
MODULE_LICENSE(“GPL”);
你是否還在尋找穩(wěn)定的海外服務(wù)器提供商?創(chuàng)新互聯(lián)www.cdcxhl.cn海外機房具備T級流量清洗系統(tǒng)配攻擊溯源,準確流量調(diào)度確保服務(wù)器高可用性,企業(yè)級服務(wù)器適合批量采購,新人活動首月15元起,快前往官網(wǎng)查看詳情吧