首页 > 系统相关 >Linux(fedora 10)Hello World模块

Linux(fedora 10)Hello World模块

时间:2022-12-13 18:04:44浏览次数:49  
标签:opt 10 fedora modules driver Linux root hello localhost


 

一个内核模块的例子:

 

#include <linux/init.h>
#include <linux/module.h>
MODULE_LICENSE("GPL");
static int hello_init(void)
{
printk(KERN_ALERT"hello,world!/n");
return 0;
}
static void hello_exit(void)
{
printk(KERN_ALERT"Goodbye,cruel world!/n");
}
module_init(hello_init);
module_exit(hello_exit);


Makefile文件


 

ifneq ($(KERNELRELEASE),)
obj-m := hello.o
else
KERNELDIR ?= /usr/src/kernels/$(shell uname -r)
PWD := $(shell pwd)
INSTALLDIR = /opt/rootfs/lib/modules
modules:
$(MAKE) -C $(KERNELDIR) M=$(PWD) modules
modules_install:
cp hello.ko $(INSTALLDIR)
clean:
rm -rf *.o *~core .depend .*.cmd *.ko *.mod.c .tmp_versions
.PHONY:modules modules_install clean
endif

 

在shell下

 


[root@localhost hello_driver]# 
make




make -C /usr/src/kernels/2.6.27.5-117.fc10.i686 M=/opt/hello_driver modules




make[1]: Entering directory `/usr/src/kernels/2.6.27.5-117.fc10.i686'




CC [M] /opt/hello_driver/hello.o




Building modules, stage 2.




MODPOST 1 modules




CC /opt/hello_driver/hello.mod.o




LD [M] /opt/hello_driver/hello.ko




make[1]: Leaving directory `/usr/src/kernels/2.6.27.5-117.fc10.i686'




[root@localhost hello_driver]#
ls




hello.c hello.mod.c hello.o Makefile~ modules.order




hello.ko hello.mod.o Makefile Module.markers Module.symvers




[root@localhost hello_driver]#
insmod hello.ko




[root@localhost hello_driver]#
lsmod | grep hello




hello 5248 0




[root@localhost hello_driver]#
rmmod hello




[root@localhost hello_driver]#
tail -n 2 /var/log/messages




Jun 23 19:33:39 localhost kernel: hello,world!




Jun 23 19:33:55 localhost kernel: Goodbye,cruel world!




[root@localhost hello_driver]#
dmesg | tail

标签:opt,10,fedora,modules,driver,Linux,root,hello,localhost
From: https://blog.51cto.com/u_15911341/5934949

相关文章

  • VS2008(SP1)资源编译错误:fatal error RC1015: cannot open include file 'afxres.h'.
    只要一改动资源,按F7编译就会出现两个错误:errorRC2001:newlineinconstantfatalerrorRC1015:cannotopenincludefile'afxres.h'.打开rc文件发现 #include"afxr......
  • linux ssh pem登录
    生成pem文件的过程:su切换到需要登录的用户下#生成公、私钥ssh-keygen-trsa-b2048-v#将私钥内容copy给pemcp~/.ssh/id_rsatest.pem#将公钥内容重定向给au......
  • Linux网络设置
    一、基础网络命令1.查看网络配置1.1查看网络接口信息ifconfig  用法:1)ifconfig  具体网卡名称       #只显示具体网卡的详细信息(无论该网卡是否......
  • linux目录结构
    所有目录都在根目录下/目录名作用bin存放2进制可执行命令的目录,例如mkdir,cat等sbin只供系统管理员使用,例如ifconfig,initdev设备文件存放目录,例如鼠......
  • Linux NTP工具的基本使用
    NTP时间同步NTP(NetworkTimeProtocol)协议,网络时间协议。利用ntp协议可以实现网络中的计算机时间同步。实现NTP协议的工具:ntpdate:只能同步一次时间ntp:持久同步时......
  • Linux命名空间之网络命名空间netns
    目录​​使用​​​​范例​​​​参考​​使用范例参考https://mp.weixin.qq.com/s/lscMpc5BWAEzjgYw6H0wBw......
  • linux top 指令各列含义
    Linux的top指令用于显示机器上正在运行的进程的信息。下面是top指令各列的含义:PID:进程ID,用于标识进程。USER:进程所有者的用户名。PR:进程优先级。NI:进程的“nice......
  • ASEMI肖特基二极管MBR20100FCT图片,MBR20100FCT大小
    编辑-ZASEMI肖特基二极管MBR20100FCT参数:型号:MBR20100FCT最大重复峰值反向电压(VRRM):100V最大RMS电桥输入电压(VRMS):70V最大直流阻断电压(VDC):100V最大平均正向整流输出电......
  • 华中师范大学2010年数学分析考研试题参考解答
    华中师范大学2010年数学分析考研试题参考解答......
  • win102-Windows环境下pycharnpython安装版下载、配置(win10-x64位32g内存)
    win102-Windows环境下pycharnpython安装版下载、配置(win10-x64位32g内存)1、建议首先安装anaconda(注意配置path环境)。  python国内镜像地址:http://npm.taobao.org/mirr......