[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. Android-自定义PopupWindow

    PopupWindow在应用中应该是随处可见的,很常用到,比如在旧版本的微信当中就用到下拉的PopupWindow,那是自定义的.新版微信5.2的ActionBar,有人已经模仿了它,但微信具体是使用 ...

  2. 我对Laravel ThinkPHP Yii symfony2 CI cakephp 的看法

    这是我的真心体会,在尝试使用Laravel.ThinkPHP.Yii.symfony2.CI.cakephp.Yii2 之后的真实想法(default7#zbphp.com). 1)ThinkPHP ...

  3. [ES6] Promise

    How to use: export default function getReplies(topicId){ return new Promise(function( resolve, rejec ...

  4. [AngularJS] Using AngularJS's ngClass

    .blue{ color: blue } .bold{ font-weight: bold; } .large{ font-size: 40px; } ngClass can accept an ar ...

  5. android怎样写一个循环文字滚动的TextView

    效果图: 在layout中这样来声明: <com.kaixin001.view.ScrollText android:id="@+id/news_statustxt" and ...

  6. mevan引入容联云通讯jar

    首先从官网下载jar 然后拷贝到lib目录下 最后在pom.xml中这样写 <dependency> <groupId>cn.com</groupId> <a ...

  7. USB 管道 && 端点

    管道是对主机和usb设备间通信流的抽象.      管道和usb设备中的端点一一对应,一个usb设备含有多少个端点,其和主机进行通信时就可以使用多少条管道,且端点的类型决定了管道中数据的传输类型.  ...

  8. C#。总结

    数据类型--变量与常量--运算符与表达式--语句(if,for)--数组--函数--结构体一.数据类型: (一)内建类型 整型(int short long byte uint ushort ulon ...

  9. bootstrap table使用小记

    bootstrap table是一个非常不错的,基于bootstrap的插件,它扩展和丰富了bootstrap表格的操作,如格式化表格,表格选择器,表格工具栏,分页等等. 最近基于bootstrap开 ...

  10. C#简单注册表操作实例

    1.简介操作 //设置注册值 private void Button_Click(object sender, RoutedEventArgs e) { //路径及间隔符号要正确 //1.如果指定路径 ...