1:简单代码

#include<linux/init.h>
#include<linux/module.h> MODULE_LICENSE("GPL");
MODULE_AUTHOR("jiuyueguang");
MODULE_DESCRIPTION("SIMPLE MODULE DRIVER"); static int hello_init(void){
printk(KERN_INFO"hello word\n");
return ;
}
static void hello_exit(void){
printk(KERN_INFO"hello word exit\n");
}
module_init(hello_init);
module_exit(hello_exit);

2:查看printk输出信息

 dmesg | tail 

3:带参数类型的模块简单代码

#include<linux/init.h>
#include<linux/module.h> MODULE_LICENSE("GPL");
MODULE_AUTHOR("jiuyueguang");
MODULE_DESCRIPTION("SIMPLE MODULE DRIVER"); static char *name="no name";
static int age=; static int hello_init(void){
printk(KERN_INFO"hello word name=%s and age=%d\n",name ,age);
return ;
}
static void hello_exit(void){
printk(KERN_INFO"hello word exit name=%s and age=%d \n",name ,age);
}
module_init(hello_init);
module_exit(hello_exit);
module_param(name,charp,S_IRUGO);
module_param(age,int,S_IRUGO);

安装带参数的模块:

sudo insmod hello_param.ko    

安装的时候没有加参数,采用程序中的默认值输出:

hello word name=no name and age=

安装的时候加参数:

sudo insmod hello_param.ko name='jiuyueguang' age=

输出:

hello word name=jiuyueguang and age=

4:我自己的Makefile

ifeq ($(KERNELRELEASE),)
KERNELDIR ?= /lib/modules/$(shell uname -r)/build
PWD := $(shell pwd)
modules:
$(MAKE) -C $(KERNELDIR) M=$(PWD) modules
modules_install:
$(MAKE) -C $(KERNELDIR) M=$(PWD) modules_install
clean:
rm -rf *.o *~ core .depend .*.cmd *.ko *.mod.c .tmp_versions Module* module* a.out
.PHONY: modules modules_install clean
else
obj-m := hello_param.o //每次修改这里就够了
endif

ubuntu动态加载模块简单模板的更多相关文章

  1. Python3的动态加载模块简单实例

    import os import sys import time import myconfig b = ['123'] a = os.path.abspath(myconfig.__file__) ...

  2. OrchardCore 如何动态加载模块?

    前言 今天,我们再次讨论下OrchardCore,通过初期调研,我们项目采用OrchardCore底层设施支持模块化,同时根据业务场景,额外还需支持二次开发,于是有了本文,若有不同解决方案,欢迎留言探 ...

  3. stevedore动态加载模块

    stevedore动态加载模块,stevedore使用setuptools的entry points来定义并加载插件.entry point引用的是定义在模块中的对象,比如类.函数.实例等,只要在im ...

  4. DevExpress XtraReport - 动态加载报表布局模板

    XtraReport的报表模板文件是.repx,下面的代码演示动态加载报表布局模板. XtraReport mReport = new XtraReport(); mReport.LoadLayout ...

  5. Python_getattr+__import__ 实现动态加载模块、类对象或函数

    __import__() 语法 __import__(name[, globals[, locals[, fromlist[, level]]]]) 参数 name -- 字符串,模块的导入路径 说明 ...

  6. AngularJs 动态加载模块和依赖

    最近项目比较忙额,白天要上班,晚上回来还需要做Angular知识点的ppt给同事,毕竟年底要辞职了,项目的后续开发还是需要有人接手的,所以就占用了晚上学习的时间.本来一直不打算写这些第三方插件的学习笔 ...

  7. [driver]linux内核动态加载模块

    问题: 1. 把编译好的模块放到板子/lib/modules对应文件夹下,并且执行了depmod -a, 比如pl2303.ko, 那么下一次插入pl2303的串口线,是否可以识别,也就是自动加载pl ...

  8. angular-ui-router动态加载模块

    1.定义index.html主页,对于通用的js就不用require依赖加载了,其中main.js作为主模块,用require添加系统路由模块. <!DOCTYPE html> <h ...

  9. nginx平滑升级、在线添加模块(tengine 动态加载模块)

    http://www.orzace.com/how-to-upgrade-nginx/ 下面是nginx替换成tengine再加上lua 模块,(tengine-2.0.1版本暂时无法动态加载lua模 ...

随机推荐

  1. js拖拽效果的实现

    1.最基础的写法 <!DOCTYPE HTML> <html> <head> <meta charset="utf-8"> < ...

  2. [Python Cookbook] Numpy: How to Apply a Function to 1D Slices along the Given Axis

    Here is a function in Numpy module which could apply a function to 1D slices along the Given Axis. I ...

  3. Careercup | Chapter 4

    二叉查换树,左孩子小于等于根,右孩子大于根. 完全二叉树,除最后一层外,每一层上的节点数均达到最大值:在最后一层上只缺少右边的若干结点. complete binary tree 满二叉树,完美二叉树 ...

  4. qt使用

    1安装qt软件(.run文件) . chmod 777 qt.....run ./qt...run或sudo ./qt...run(安装目录不一样) 2.sudo gedit .bashrc添加以下内 ...

  5. DevExpress右键菜单使用 z

    添加BarManager和popupMenu组建: 设置popupMenu组件的Manager属性: 右键点击popupMenu主键,点击Customize选项添加菜单:    然后便可添加到鼠标事件 ...

  6. WPA2密钥重装攻击原理分析

    这两天最火爆的莫过 “WPA2被破解” 这一条大新闻了.我对其原理非常感兴趣,苦于没有找到的文献,所以就整理这么一篇,方便自己和大家理解.主要是根据目前发布的文章以及一些相关资料. 壹.WPA2的机制 ...

  7. elasticsearch 查询模板

    简单版示例: 2.x版本(相比于1.x版本,使用bool替代filtered,使用must替代query) { "query": { "bool": { &qu ...

  8. Resolving 'Root Partition Is Filling Up' Issue on Sophos UTM Firewall

    from: https://wandersick.blogspot.com/2016/06/resolving-root-partition-is-filling-up.html This is a ...

  9. Win7安装软件,界面上中文显示乱码的解决方案

    “Control panel”->"Clock,Language and Region"->"Region and Language"->第四 ...

  10. Android二维码工具zxing使用

    二维码在我们生活中随处可见.在我眼里简直能够用"泛滥"来形容啦.那怎样在我们Android项目中扫描识别二维码或生成二维码图片呢? 我们通常使用的开源框架是zxing.在githu ...