sudo gedit hello.c

   #include <linux/module.h>
#include <linux/kernel.h>
#include <linux/init.h>
MODULE_LICENSE("GPL");
MODULE_AUTHOR("leemo");
MODULE_DESCRIPTION("Hello World Module");
MODULE_ALIAS("a simplest module");
static int __init hello_init(void)
{
printk(KERN_EMERG"Hello World! This is leemo's work\n");
return 0;
}
static void __exit hello_exit(void)
{
printk("<6>hello exit\n");
return;
}
module_init(hello_init);
module_exit(hello_exit);

sudo gedit Makefile

bj-m := hello.o
DIR := /lib/modules/$(shell uname -r)/build
ll:
make -C $(KDIR) M=$(PWD) modules
lean:
rm *.o *.ko Mo* mo* *.mo*

编译

make

加载模块

sudo insmod hello.ko

使用lsmod查看模块

使用dmesg查看

完成。

卸载模块

rmmod  hello.ko.

【原创】Linux 内核模块编程的更多相关文章

  1. linux内核模块编程实例

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

  2. Linux内核模块编程——Hello World模块

    Linux内核模块编程 编程环境 Ubuntu 16.04 LTS 什么是模块 内核模块的全称是动态可加载内核模块(Loadable Kernel Modul,KLM),可以动态载入内核,让它成为内核 ...

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

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

  4. Linux内核模块编程可以使用的内核组件

    2.2.2 在阅读<深入Linux内核架构与底层原理> 作者:刘京洋 韩方,发现一些错误,有些自己的理解,特以此记录 1.工作队列(workqueue) 队列是一种可以先进先出的数据结构, ...

  5. 1.Linux内核模块编程

    1.模块加载程序结构 - 模块加载函数: static int _init init_function(void); module_init(init_function); - 模块卸载函数: sta ...

  6. inux内核模块编程入门

    linux内核模块编程入门 2013-07-06 23:59:54 分类: LINUX 原文地址:linux内核模块编程入门 作者:s270768095 模块编程属于内核编程,因此,除了对内核相关知识 ...

  7. linux内核编程入门--系统调用监控文件访问

    参考的资料: hello world   https://www.cnblogs.com/bitor/p/9608725.html linux内核监控模块--系统调用的截获  https://www. ...

  8. 《linux内核设计与分析》内核模块编程

    内核模块编程 一.准备工作 虚拟机:VMware Workstation 12操作系统:ubuntu当前内核版本:linux-headers-4.4.0-22-generic 二.有关于内核模块的知识 ...

  9. linux动态内核模块编程-3

    将一组与模块相关的命令加载进内核 完成功能类似2,打印proc下的相关信息.但是不用重新编译内核,节省时间,更为灵活 内核模块介绍 模块是在内核空间运行的程序,实际上是一种目标文件,不能单独运行但其代 ...

随机推荐

  1. A Tour of Go Range

    The range form of the for loop iterates over a slice or map. package main import "fmt" , , ...

  2. A Tour of Go For

    Go has only one looping construct, the for loop. The basic for loop looks as it does in C or Java, e ...

  3. java常见算法

    1.冒泡排序 public int[] bubbleSort(int arr){ int temp; boolean isOk; for(int i = 0; i < arr.length; i ...

  4. SQL Server tables export/import with bcp

    Export tables below bcp wind.wind.WTUser OUT c:\WTUser.bcp -T -N bcp wind.wind.EPPlan OUT c:\EPPlan. ...

  5. [2014.5.22][UBUNTU]Ubuntu与Windows系统时间不同步的问题

    安装Ubuntu+Windows双系统时会遇到Windows和Ubuntu系统时间不同步的问题,这是由于Windows系统默认读取主板bios等硬件系统时间作为OS的当地时间;而MAc,Linux类的 ...

  6. window nginx 启动无提示错误,却没有listen 80port

    一直使用虚拟机来使用web+hostonly方式; 今天为了測试一个php平台的window系统兼容性, 在官方下载了window-nginx 1.9.1版本号; 解压到文件夹, 执行nginx.ex ...

  7. apache+php配置中遇到的问题

    在安装apache+php配置中遇到的问题: LoadModule php5_module "D:/PHP/php5apache2_4.dll"PHPIniDir "D: ...

  8. linux调度器 信息解读

    http://blog.csdn.net/wudongxu/article/category/791519

  9. FAQ系列 | 解读EXPLAIN执行计划中的key_len

    http://imysql.com/2015/10/20/mysql-faq-key-len-in-explain.shtml

  10. 【十分钟教会你汇编】MIPS编程入门(妈妈说标题要高大上,才会有人看>_<!)

    无意中找到一篇十分好用,而且篇幅也不是很大的入门教程,通篇阅后,再把“栗子”敲一遍,基本可以有一个比较理性的认识,从而方便更好地进一步深入学习. 废话不多说,上干货(英语好的直接跳过本人的渣翻译了哈— ...