最简单的内核模块hello world
[root@localhost /home/ahao.mah/main]
#cat hello.c
// Defining __KERNEL__ and MODULE allows us to access kernel-level code not usually available to userspace programs.
#undef __KERNEL__
#define __KERNEL__
#undef MODULE
#define MODULE
// Linux Kernel/LKM headers: module.h is needed by all modules and kernel.h is needed for KERN_INFO.
#include <linux/module.h> // included for all kernel modules
#include <linux/kernel.h> // included for KERN_INFO
#include <linux/init.h> // included for __init and __exit macros
static int __init hello_init(void)
{
printk(KERN_INFO "Hello world!\n");
return 0; // Non-zero return means that the module couldn't be loaded.
}
static void __exit hello_cleanup(void)
{
printk(KERN_INFO "Cleaning up module.\n");
}
module_init(hello_init);
module_exit(hello_cleanup);
[root@localhost /home/ahao.mah/main]
#cat Makefile
obj-m := hello.o
KDIR := /lib/modules/$(shell uname -r)/build
PWD := $(shell pwd)
all:
$(MAKE) -C $(KDIR) M=$(PWD) modules
clean:
$(MAKE) -C $(KDIR) M=$(PWD) clean
[root@localhost /home/ahao.mah/main]
#ll Makefile hello.c
-rw-r--r-- 1 root root 785 Dec 21 15:48 hello.c
-rwxr-xr-x 1 root root 170 Dec 21 15:51 Makefile
[root@localhost /home/ahao.mah/main]
#make
make -C /lib/modules/3.10.0-327.ali2000.alios7.x86_64/build M=/home/ahao.mah/main modules
make[1]: Entering directory `/usr/src/kernels/3.10.0-327.ali2000.alios7.x86_64'
CC [M] /home/ahao.mah/main/hello.o
Building modules, stage 2.
MODPOST 1 modules
CC /home/ahao.mah/main/hello.mod.o
LD [M] /home/ahao.mah/main/hello.ko
make[1]: Leaving directory `/usr/src/kernels/3.10.0-327.ali2000.alios7.x86_64'
[root@localhost /home/ahao.mah/main]
#ls
hello.c hello.ko hello.mod.c hello.mod.o hello.o Makefile modules.order Module.symvers
[root@localhost /home/ahao.mah/main]
#lsmod | grep hello
[root@localhost /home/ahao.mah/main]
#insmod hello.ko
[root@localhost /home/ahao.mah/main]
#lsmod | grep hello
hello 12428 0
[root@localhost /home/ahao.mah/main]
#tail /var/log/messages
Dec 21 15:52:43 rt2m09617 kernel: hello: module license 'unspecified' taints kernel.
Dec 21 15:52:43 rt2m09617 kernel: Disabling lock debugging due to kernel taint
Dec 21 15:52:43 rt2m09617 kernel: hello: module verification failed: signature and/or required key missing - tainting kernel
Dec 21 15:52:43 rt2m09617 kernel: Hello world!
最简单的内核模块hello world的更多相关文章
- 编写简单的内核模块及内核源码下载,内核模块Makefile编写
CentOS的内核源码默认是没有下载的,需要自己下载,首先安装linux的时候就应该知道linux的版本,我装的是Centos7的 下面查一下内核的版本,使用下面的命令 [scut_lcw@local ...
- Linux内核驱动学习(一)编写最简单Linux内核模块HelloWorld
文章目录 准备工作 什么是内核模块 编写 hello.c 模块编译 相关指令 测试结果 模块加载 模块卸载 准备工作 在进行以下操作前,首先我准备了一台电脑,并且安装了虚拟机,系统是Ubuntu16. ...
- 【Linux】【Kernel】一个简单的内核模块例子
1.本地主机的参数 zhangjun@zhangjun-virtual-machine:~$ uname -a Linux zhangjun-virtual-machine 4.4.0-31-gene ...
- 编写简单Linux内核模块
模块代码如下 //main.c #include <linux/kernel.h> #include <linux/module.h> #include <linux/i ...
- ARM平台的内核模块编写与安装
Linux 系统一直在不断地发展,而相应地她的代码量也在不断的增大,直接导致的结果就是她的可执行镜像就变得越来越庞大.那么问题来了,如果将所有的镜像文件一次性地复制到内存中,那么所需的空间就非常 ...
- linux内核模块编程实例
linux内核模块编程实例 学号:201400814125 班级:计科141 姓名:刘建伟 1.确定本机虚拟机中的Ubuntu下Linux的版本 通过使用命令uname -a/uname -r/una ...
- Linux:32/64位程序(应用程序、共享库、内核模块)
摘要: Linux系统区分32/64位,相应地,应用程序.共享库和内核模块也区分32/64位. 本文以Ubuntu系统为例,介绍如何编译和使用32/64位的应用程序.共享库和内核模块. 1. 应用程序 ...
- Linux内核模块编写详解
内核编程常常看起来像是黑魔法,而在亚瑟 C 克拉克的眼中,它八成就是了.Linux内核和它的用户空间是大不相同的:抛开漫不经心,你必须小心翼翼,因为你编程中的一个bug就会影响到整个系统,本文给大家介 ...
- Linux内核模块编程与内核模块LICENSE -《具体解释(第3版)》预读
Linux内核模块简单介绍 Linux内核的总体结构已经很庞大,而其包括的组件或许多.我们如何把须要的部分都包括在内核中呢?一种方法是把全部须要的功能都编译到Linux内核.这会导致两个问题.一是生成 ...
随机推荐
- psp个人软件过程需求文档
1. 业务需求 1.1 应用背景 开发软件项目进度计划总是那么不准确,延期经常出现,跟可恨的是甚至无法给出一个相对比较明确的延迟时间.很大 因素在于分配给开发人员的完成时间与开发人员的实际完成时间有 ...
- C#委托与事件之观察者Observer设计模式
前言 委托: 委托是一种在对象里保存方法引用的类型,同时也是一种类型安全的函数指针. 或委托可以看成一种表示函数的数据类型,类似函数指针. 事件是特殊的委托 观察者模式:两种角色:(1)Subj ...
- Android学习【Android内核编译流程和错误笔记】
博客:http://blog.csdn.net/muyang_ren Ubuntu14.04 LTS(要求是64位长期支持版LTS) Jdk1.8 内核:android4.0 一:jdk 1.解压jd ...
- Hadoop 开源调度系统zeus(二)
紧跟之前Hadoop 开源调度系统zeus(一) 本节主要介绍一下zeus的架构: 先给一个zeus的架构图 无论Master还是Worker都有一套WEB UI,无论从哪个上面去看,看到的结果都是一 ...
- 解决Android单个dex文件不能超过65536个方法问题
当我们的项目代码过大时,编译运行时会报Unable to execute dex: method ID not in[0, 0xffff]: 65536)错误.当出现这个错误时说明你本身自己的工程代码 ...
- IIS7 常用模块介绍说明
1.1.0 IIS常用的功能模块介绍: 1) 静态内容:可发布静态 Web 文件格式,比如 HTML 页面和图像文件. 2) 默认文档:允许您配置当用户未在 URL ...
- Linux下彻底删除oracle步骤【转】
(1)关闭oracle服务和后台进程 <1>查看安装的主目录和环境变量: echo $ORACLE_HOME env | grep ORA <2>查看实例名 sqlplus ...
- CGRectInset CGRectoffset UIEdgeInsetsInsetRect 这三个函数的使用情况
//CGRectInset 将原来的矩形放大或者缩小,正表示缩小,-表示放大. CGRect rect= CGRectMake(20, 50, 100, 80); CGRect rect1=CGRec ...
- iOS_SN_CocoaPods使用详细说明( 转)
一.概要 iOS开发时,项目中会引用许多第三方库,CocoaPods(https://github.com/CocoaPods/CocoaPods)可以用来方便的统一管理这些第三方库. 二.安装 由于 ...
- C#高级知识点概要(3) - 特性、自动属性、对象集合初始化器、扩展方法、Lambda表达式和Linq查询
1.特性(Attributes) 特性(Attributes),MSDN的定义是:公共语言运行时允许你添加类似关键字的描述声明,叫做attributes, 它对程序中的元素进行标注,如类型.字段.方法 ...