helloworld.c 代码

#include <linux/init.h>
#include <linux/module.h> MODULE_LICENSE("Dual BSD/GPL"); static int hello_init(void)
{
printk(KERN_ALERT "Hello world\n");
return ;
} static void hello_exit(void)
{
printk(KERN_ALERT "goodbye,cruel world\n");
} module_init(hello_init);
module_exit(hello_exit);

Makefile 代码

 obj-m := helloworld.o

 CURRENT_DIR :=$(shell pwd)

 KERNEL_DIR := /usr/src/linux-headers-$(shell uname -r)

 all:
$(MAKE) -C $(KERNEL_DIR) M=$(CURRENT_DIR) modules clean:
rm -rf %.o

执行make

 ryan@Ryan-pc:/data1/Ryan/demo/helloworld$ make
make -C /usr/src/linux-headers-3.13.--generic M=/data1/Ryan/demo/helloworld modules
make[]: Entering directory `/usr/src/linux-headers-3.13.--generic'
Building modules, stage .
MODPOST modules
make[]: Leaving directory `/usr/src/linux-headers-3.13.--generic'

加载模块

 ryan@Ryan-pc:/data1/Ryan/demo/helloworld$ sudo insmod helloworld.ko
ryan@Ryan-pc:/data1/Ryan/demo/helloworld$

dmesg查看

 ryan@Ryan-pc:/data1/Ryan/demo/helloworld$ dmesg
 [178401.813566] sr :::: [sr0] Device not ready
[178401.813570] sr :::: [sr0]
[178401.813571] Result: hostbyte=DID_OK driverbyte=DRIVER_SENSE
[178401.813572] sr :::: [sr0]
[178401.813573] Sense Key : Not Ready [current]
[178401.813575] sr :::: [sr0]
[178401.813577] Add. Sense: Medium not present - tray closed
[178401.813579] sr :::: [sr0] CDB:
[178401.813580] Read(): 2f
[178401.813584] end_request: I/O error, dev sr0, sector
[179614.794066] helloworld: module verification failed: signature and/or required key missing - tainting kernel
[179614.794552] Hello world
[180458.268623] goodbye,cruel world
[180514.941519] Hello world
[180549.136795] goodbye,cruel world
[181244.193514] Hello world

卸载模块

 ryan@Ryan-pc:/data1/Ryan/demo/helloworld$ sudo rmmod helloworld
ryan@Ryan-pc:/data1/Ryan/demo/helloworld$

最新文章

  1. SELECT INTO 和 INSERT INTO区别
  2. 网页爬虫--scrapy入门
  3. oracle portlist.ini
  4. 域名服务器--DNS
  5. javascript判断NaN
  6. unity3d学习笔记(十九)--ngui制作3d人物头顶的头像和血条
  7. CI框架篇之模型篇--初识(1)
  8. hive 使用脚本清洗数据:时间戳转日期
  9. Android中倒计时代码
  10. 【解题报告】Math
  11. asp.net core mvc权限控制:分配权限
  12. java.lang.NoClassDefFoundError: org/apache/jsp/jsp/Container_jsp
  13. MVC 的 Razor引擎显示代码表达式与隐式代码表达式
  14. JAVA(五)反射机制/Annotation
  15. android linux 内核层
  16. JedisConnectionPool scala
  17. Nginx/LVS/HAProxy负载均衡软件的优缺点详解【转】
  18. React Native网络编程之Fetch
  19. ORACLE—005:创建JOB(一)
  20. Vim技能修炼教程(3) - 语法高亮进阶

热门文章

  1. 29最小的K个数
  2. 【工具】PC端调试手机端 Html 页面的工具
  3. @@fetch_status
  4. 【JavaScript】满天星
  5. Apache 优化
  6. Linux内核优化项
  7. Introspector内省和反射的区别.
  8. timer使用方法
  9. 分享:JAVA各种对象
  10. android传感器使用