Skip navigation.

Linux Kernel Programming: Kernel Module

Note: Develop and Test using UML

The Linux Kernel Module Programming Guide

A simple kernel module from the book "Linux Device Driver"
/*                                                     
 * $Id: hello.c,v 1.5 2004/10/26 03:32:21 corbet Exp $ 
 */                                                    
#include <linux/init.h>
#include <linux/module.h>
MODULE_LICENSE("Dual BSD/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);


A Makefile
obj-m:= hello.o
KDIR:= /home/work/uml/linux-2.6.18
PWD:= $(shell pwd)
default:
$(MAKE) -C $(KDIR) SUBDIRS=$(PWD) modules ARCH=um
clean:
rm -f *.o *.ko *.mod.c


Upload module to UML instance
ubuntu# mkdir -p /lib/modules/2.6.18/bob
host# make
host# scp -r /path-to-code/hello.ko 
      root@192.168.1.2:/lib/modules/2.6.18/bob/


Test module
ubuntu# depmod -a
ubuntu# modprobe hello
ubuntu# rmmod hello

Configure Ruby on Rails in Debian EtchLinux Kernel Programming: System Calls

How to use Quote function:

  1. Select some text
  2. Click on the Quote link

Write a comment

Comment
(BBcode and HTML is turned off for anonymous user comments.)

If you can't read the words, press the small reload icon.


Smilies