hello world

hello.c

#include<linux/init.h>
#include<linux/kernel.h>
#include<linux/module.h>
MODULE_LICENSE("Dual BSD/GPL");
static int hello_init(void)
{
printk(KERN_EMERG "Hello ,Linux Driver!\n");
return 0;
}
static void hello_exit(void)
{
printk(KERN_EMERG "Hello Diver Exit !\n");
}
module_init(hello_init);
module_exit(hello_exit);

 

Makefile

obj-m := hello.o

#KERNELDIR := /lib/modules/2.6.24-21-generic/build
#KERNELDIR := /usr/src/linux-headers-2.6.24-21-generic/
KERNELDIR := /lib/modules/$(shell uname -r)/build

PWD := $(shell pwd)

modules:
$(MAKE) -C $(KERNELDIR) M=$(PWD) modules
clean:
rm -rf *.o *~ core .depend .*.cmd *.ko *.mod.c .tmp_versions

 

make


加载 查看

#insmod hello.ko

#lsmod

#rmmod hello


 

你可能感兴趣的:(Hello world)