views:

121

answers:

2

Yes, as the title, I don't know how to program and compile "Hello World" code in kernel mode of linux , please help me in the shortest and easy to understand way. Thank you ! (Any related document is welcomed too, I'm just new to this)

+5  A: 

You can start Here:

/*  
 *  hello-1.c - The simplest kernel module.
 */
#include <linux/module.h>   /* Needed by all modules */
#include <linux/kernel.h>   /* Needed for KERN_INFO */

int init_module(void)
{
    printk(KERN_INFO "Hello world 1.\n");

    /* 
     * A non 0 return means init_module failed; module can't be loaded. 
     */
    return 0;
}

void cleanup_module(void)
{
    printk(KERN_INFO "Goodbye world 1.\n");
}
fseto
+1  A: 

Wow, that's a question!

Just think first that the Linux kernel has no terminal, no direct interaction with the user. A Hello World cannot be invoked as any other user program on the command line. The best fit I can think of is a character device driver implemented as a kernel module that would read "Hello World" on device /dev/helloworld for example.

I can point you to reading the book from Rubini: Linux Device Drivers. It explains and has examples to create simple Hello World kind of kernel modules.

Didier Trosset
Thank everyone, I have just finished my 1st "Hello World" in kernel mode. So much fun on this "programming depth" :)
Dark Cloud