Skip to contentSkip to conversation

'hello world' module

DISCUSSION Nick Warne 1 participant 1 message Jun 11, 2005

lore
Share & tools
lore

Nick Warne

author
#0 lore raw

Hi Ilan,

I don't know about the Oh Really! version, but this one taken from 'Beginning Linux Programming' (forward by Alan Cox!) ISBN 1-861002-97-1 worked OK for me.

2.4.31, GCC 3.4.4

Build like:

gcc -D__KERNEL__ -I/usr/src/linux/include -DMODULE -Wall -O2 -c hello.c -o hello.o

Edit hello.c to suit:

#include <linux/module.h>

#if defined(CONFIG_SMP)
#define __SMP__
#endif

#if defined(CONFIG_MODVERSIONS)
#define MODVERSIONS
#include <linux/modversions.h>
#endif

#include <linux/kernel.h>

MODULE_AUTHOR ("Nick Warne <[email protected]>");
MODULE_DESCRIPTION ("Hello Kernel! module");
MODULE_LICENSE("GPL");

int init_module(void)

{
        printk(KERN_DEBUG "Hello, kernel!\n");
        return 0;
}

void cleanup_module(void)

{
        printk(KERN_DEBUG "Good-bye, kernel!\n");
}

bash-2.05b# insmod hello.o
bash-2.05b# dmesg | tail -n1
Hello, kernel!

bash-2.05b# lsmod
Module Size Used by Tainted: P
hello 320 0 (unused)

bash-2.05b# rmmod hello
bash-2.05b# dmesg | tail -n1
Good-bye, kernel!

Hope that helps.

Nick

Signature · 2 lines
"When you're chewing on life's gristle,
Don't grumble, Give a whistle..."