[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的更多相关文章

  1. 编写简单的内核模块及内核源码下载,内核模块Makefile编写

    CentOS的内核源码默认是没有下载的,需要自己下载,首先安装linux的时候就应该知道linux的版本,我装的是Centos7的 下面查一下内核的版本,使用下面的命令 [scut_lcw@local ...

  2. Linux内核驱动学习(一)编写最简单Linux内核模块HelloWorld

    文章目录 准备工作 什么是内核模块 编写 hello.c 模块编译 相关指令 测试结果 模块加载 模块卸载 准备工作 在进行以下操作前,首先我准备了一台电脑,并且安装了虚拟机,系统是Ubuntu16. ...

  3. 【Linux】【Kernel】一个简单的内核模块例子

    1.本地主机的参数 zhangjun@zhangjun-virtual-machine:~$ uname -a Linux zhangjun-virtual-machine 4.4.0-31-gene ...

  4. 编写简单Linux内核模块

    模块代码如下 //main.c #include <linux/kernel.h> #include <linux/module.h> #include <linux/i ...

  5. ARM平台的内核模块编写与安装

       Linux 系统一直在不断地发展,而相应地她的代码量也在不断的增大,直接导致的结果就是她的可执行镜像就变得越来越庞大.那么问题来了,如果将所有的镜像文件一次性地复制到内存中,那么所需的空间就非常 ...

  6. linux内核模块编程实例

    linux内核模块编程实例 学号:201400814125 班级:计科141 姓名:刘建伟 1.确定本机虚拟机中的Ubuntu下Linux的版本 通过使用命令uname -a/uname -r/una ...

  7. Linux:32/64位程序(应用程序、共享库、内核模块)

    摘要: Linux系统区分32/64位,相应地,应用程序.共享库和内核模块也区分32/64位. 本文以Ubuntu系统为例,介绍如何编译和使用32/64位的应用程序.共享库和内核模块. 1. 应用程序 ...

  8. Linux内核模块编写详解

    内核编程常常看起来像是黑魔法,而在亚瑟 C 克拉克的眼中,它八成就是了.Linux内核和它的用户空间是大不相同的:抛开漫不经心,你必须小心翼翼,因为你编程中的一个bug就会影响到整个系统,本文给大家介 ...

  9. Linux内核模块编程与内核模块LICENSE -《具体解释(第3版)》预读

    Linux内核模块简单介绍 Linux内核的总体结构已经很庞大,而其包括的组件或许多.我们如何把须要的部分都包括在内核中呢?一种方法是把全部须要的功能都编译到Linux内核.这会导致两个问题.一是生成 ...

随机推荐

  1. 常用JS模板

    var _win, _doc, _stt, _do = document.domain, _arr = _do.split("."); function _st() { try { ...

  2. emacs快捷键学习(一)--Linux最强大的编辑器

    emacs是一个非常强大的编辑器.经常使用的快捷键总结例如以下: 退出emacs:ctrl+x ctrl+c 移动到下一屏:ctrl+v 移动到上一屏:alt+v 将光标所在行移动到屏幕中间:ctrl ...

  3. JavaScript中函数参数的按值传递与按引用传递(即按地址传递)

    首先声明一句:JavaScript中所有函数的参数都是按值传递的!不存在按引用传递! 在讲传递参数之前我们先来讲一下指针. 学过C指针的应该都知道,指针变量中保存的是一个地址,程序可以根据所保存的地址 ...

  4. textarea固定大小,不可拖动

    写前端,经常很多小东西容易忽略忘记,今天写页面碰到设定一个输入框大小,死活记不起怎么固定,故找了一下度娘,其实添加一个css属性就好了: resize: none; 随笔记一下!

  5. linux下登录出现-bash-3.2#解决办法

    1:下载 安装 csh yum  install csh   2:再切换即可  

  6. O、Ω、Θ表示

    转载,原网址为:http://book.2cto.com/201211/8127.html 对于任何数学函数,这三个记号可以用来度量其“渐近表现”,即当趋于无穷大时的阶的情况,这是算法分析中非常重要的 ...

  7. myeclipseb笔记(4):拷贝文件的相应配置

    在MyEclipse中,经常需要用到拷贝工程文件,但是直接拷贝的话,就会出现访问不了的情况,如下: 原文件learn/StudManage/login.jsp,访问: 拷贝工程,改名,访问: 就出现了 ...

  8. 14--物理引擎Box2D

    物理模拟引擎专注于模拟现实世界中物体以及物体之间的基本运动规律.在游戏中引入物理引擎能提高游戏的真实性和可玩性,如<愤怒的小鸟>中小鸟弹出的抛物线运动.<割绳子>中割后的运动等 ...

  9. 关于 HRESULT:0x80070

    异常来自 HRESULT:0x80070057 (E_INVALIDARG) 网上看的普遍办法是: 解决方法 是 删除 C:/WINDOWS/Microsoft.NET/Framework/v2.0. ...

  10. “DataTable”是“System.Data.DataTable”和“Microsoft.Office.Interop.Excel.DataTable”之间的不明确的引用

    “DataTable”是“System.Data.DataTable”和“Microsoft.Office.Interop.Excel.DataTable”之间的不明确的引用 造成这个错误的原因是,在 ...