zoukankan      html  css  js  c++  java
  • linux如何添加内核模块

    1.编写模块代码:

      简单例子:

    #include<linux/kernel.h>
    #include<linux/module.h>
    #Inlcude<linux/init.h>
    static int __init hello_init(void)
    {
      printk(KERN_INFO "Hello world\n");
      return 0;
    }
    static void __exit hello_exit(void);
    {
      printk(KERN_INFO "Goodbye world\n");
    }
    module_init(hello_init);
    module_exit(hello_exit);

    2.编写Makefile

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

    3.运行make all 生成hello.ko文件

    4.运行命令insmod ./hello.ko装载模块,运行lsmod查看已经装载的模块

    5.运行rmmod hello 卸载模块

    6.printk()函数有8个日志级别,运行dmesg命令查看printk的输出缓冲区

  • 相关阅读:
    查看linux命令类型
    理解bashrc和profile[转载]
    问题:ldconfig
    箭头函数
    闭包函数
    方法
    手把手教你使用百度地图(图解)
    变量作用域与解构赋值
    iterable
    Map和Set
  • 原文地址:https://www.cnblogs.com/bubbler/p/2477933.html
Copyright © 2011-2022 走看看