美文网首页
编写内核的第一个hello模块

编写内核的第一个hello模块

作者: 海棠依旧_6c54 | 来源:发表于2019-08-18 18:09 被阅读0次

hello.c 

···

#include <linux/module.h>

#include <linux/kernel.h>

#include <linux/init.h>

static int __init init_hello(void)

{

printk(KERN_ALERT "my first module test,output \"hello!\"\n");

return 0;

}

static void __exit exit_hello(void)

{

printk(KERN_DEBUG "bye bye test module!\n");

}

module_init(init_hello);

module_exit(exit_hello);

MODULE_LICENSE("GPL");

MODULE_AUTHOR("xiaoan");

MODULE_VERSION("v0.1");

MODULE_DESCRIPTION("TEST FOR MODULE");

···

Makefile

```

obj-m := hello.o

KERNELBUILD :=/lib/modules/$(shell uname -r)/build

default:

make -C $(KERNELBUILD) M=$(shell pwd) modules

```

相关文章

网友评论

      本文标题:编写内核的第一个hello模块

      本文链接:https://www.haomeiwen.com/subject/iebcsctx.html