加载helloworld模块

#include <linux/version.h>
#include <linux/config.h>
#if CONFIG_MODVERSIONS==1
#define MODVERSIONS
#include <linux/modversions.h>
#endif


#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/init.h>
MODULE_LICENSE ("GPL");

static int hello_init(void)
{
  printk("helloworld/n");
  return 0;
}

static void hello_exit(void)
{
 printk("GoodBye Cruel World/n");
}
module_init(hello_init);
module_exit(hello_exit); 

编译命令:
gcc -Wall -DMODULE -D__KERNEL__ -DLINUX -c -o helloworld.o helloworld.c -I /usr/src/linux-2.4/include/

其中 -I /usr/src/linux-2.4/include/ 是用来指定头文件的路径

产生helloworld.o

insmod hello.o

rmmod hello

执行这两条命令后并没有在终端输出helloworld, goodbye cruel world!是因为printk输出优先级的问题,可以在终端下执行dmseg来查看输出!

在终端显示的问题等以后看到此知识点后再解决!

曾经出现过的问题比较普遍,可以查看以下两个帖子!

http://www.linuxsir.org/bbs/showthread.php?p=1216780

http://www.linuxsir.org/bbs/archive/index.php/t-42965.html

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值