首页 > 系统服务 > 详细

Linux kernel develop -- Hello World

时间:2015-12-09 01:52:00      阅读:312      评论:0      收藏:0      [点我收藏+]

hello.c:

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

static int hello_init(void)
{
  printk(KERN_ALERT "Hello, world!\n");
  return 0;
}

static void hello_exit(void)
{
  printk(KERN_ALERT "Goodbye, My Dear World!\n");
}

module_init(hello_init);
module_exit(hello_exit);

Makefile:

obj-m = hello.o
KVERSION = $(shell uname -r)
all:
    make -C /lib/modules/$(KVERSION)/build M=$(PWD) modules
clean:
    make -C /lib/modules/$(KVERSION)/build M=$(PWD) clean

The files:

技术分享

 

order in terminal:

make

insmod hello.ko

tail /var/log/messages(read the log of output)

rmmod hello.ko

tail /var/log/messages(read the log of output)

技术分享

Linux kernel develop -- Hello World

原文:http://www.cnblogs.com/rixiang/p/5031571.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!