最簡(jiǎn)單的Linux驅(qū)動(dòng)程序

    時(shí)間:2024-09-09 07:20:15 Linux認(rèn)證 我要投稿
    • 相關(guān)推薦

    最簡(jiǎn)單的Linux驅(qū)動(dòng)程序

      你正在學(xué)習(xí)linux嗎?你知道最簡(jiǎn)單的Linux驅(qū)動(dòng)程序是怎么樣的嗎?下面yjbys小編為大家提供最簡(jiǎn)單的Linux驅(qū)動(dòng)程序,希望對(duì)大家有所幫助!

      #include

      #include //兩個(gè)必須頭文件

      MODULE_LICENSE("Dual BSD/GPL");//GPL協(xié)議

      static char *whom = "world";//insmod傳入?yún)?shù)是用到

      static int howmany = 1;//insmod傳入?yún)?shù)是用到

      module_param(howmany,int,S_IRUGO);//傳入?yún)?shù)要用module_param宏來(lái)聲明。這樣我們就可以使用insmod命令

      //時(shí)傳入?yún)?shù),其實(shí)是模塊讓這些參數(shù)對(duì)insmod命令可見(jiàn)

      module_param(whom,charp,S_IRUGO);

      unsigned int i;

      static int hello_init(void)

      {

      printk(KERN_ALERT "Hello,world\n");

      for(i=0;i

      printk(KERN_ALERT "hello %s\n",whom);

      return 0;

      }

      static void hello_exit(void)

      {

      printk(KERN_ALERT "Goodbye, cruel world\n");

      }

      module_init(hello_init);

      module_exit(hello_exit);

      下面是Makefile文件

      obj-m += hello.o//obj-m編譯成模塊

      KERDIR = /work/linux-2.6.30.4//內(nèi)核所在目錄

      modules:

      make -C $(KERDIR) M=`pwd` modules//-C表示進(jìn)入到后面目錄里編譯,M=` `指定編譯好的文件所在目錄

      clean:

      rm -rf *.o *~core .depend *.cmd *.ko *.mod.c *.tmp_versions

      下面是加載模塊時(shí)情況

      [root@cgyl2010 ~]#insmod hello.ko howmany=10 whom="Mom"

      Hello,world

      hello Mom

      hello Mom

      hello Mom

      hello Mom

      hello Mom

      hello Mom

      hello Mom

      hello Mom

      hello Mom

      hello Mom

      這樣就可以通過(guò)insmoa命令傳進(jìn)來(lái)的參數(shù)來(lái)控制我們要實(shí)現(xiàn)的現(xiàn)象(這里是打印情況),有時(shí)候會(huì)比較方便。

    【最簡(jiǎn)單的Linux驅(qū)動(dòng)程序】相關(guān)文章:

    Linux認(rèn)證考點(diǎn)03-19

    Linux認(rèn)證的概念03-25

    Linux認(rèn)證概念03-19

    Linux認(rèn)證優(yōu)勢(shì)03-19

    學(xué)習(xí)Linux的忠告03-21

    Linux認(rèn)證系統(tǒng)管理:linux下搭建ftp03-08

    Linux認(rèn)證基本介紹03-12

    Linux認(rèn)證賬戶映射01-23

    Linux基本指令大全11-23

    91久久大香伊蕉在人线_国产综合色产在线观看_欧美亚洲人成网站在线观看_亚洲第一无码精品立川理惠

      日本精品在线亚洲视频看看 | 特黄特色三级在线看国产 | 亚洲欧美一区二区三区免费 | 在线aⅴ亚洲中文字幕 | 一级a爱做片观看免费久久 精品综合久久久久久99 | 亚洲国产a国产片精品 |