• Linux kernel develop -- Hello World


    hello.c:

    #include <linux/init.h>
    #include <linux/module.h>
    #include <linux/kernel.h>
    MODULE_LICENSE("Dual BSD/GPL");
    MODULE_AUTHOR("xudonglee");
    
    static int hello_init(void)
    {
      printk(KERN_ALERT "Hello, world!
    ");
      return 0;
    }
    
    static void hello_exit(void)
    {
      printk(KERN_ALERT "Goodbye, My Dear World!
    ");
    }
    
    module_init(hello_init);
    module_exit(hello_exit);

    Makefile:

    obj-m = hello.o
    KVERSION = $(shell uname -r)
    all:
        make -C /lib/modules/$(KVERSION)/build M=$(PWD) modules
    clean:
        make -C /lib/modules/$(KVERSION)/build M=$(PWD) clean

    The files:

    order in terminal:

    make

    insmod hello.ko

    tail /var/log/messages(read the log of output)

    rmmod hello.ko

    tail /var/log/messages(read the log of output)

  • 相关阅读:
    Investment
    The Fewest Coins
    Bone Collector II
    Cow Exhibition
    饭卡
    A + B Problem II
    F
    敌兵布阵
    单例模式
    面向对象
  • 原文地址:https://www.cnblogs.com/rixiang/p/5031571.html
Copyright © 2020-2023  润新知