Find the answer to your Linux question:
Results 1 to 2 of 2
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1

    How do I make a simple hello world module in Linux?

    I have been wanting to work on developing Linux, and one of the problems I have is that most of the documentation out there for developing Linux modules is outdated (or atleast all the documentation I have found). I read in a book called "Linux device drivers" that it got all of its information about kernel development from the documentation that comes with the kernel source code.
    However I haven't been able to find the documentation on how to write a simple module. I am using Linux version 2.6.32-32-generic.

  2. #2
    Here is a example code

    #include <linux/kernel.h>
    #include <linux/init.h>
    #include <linux/module.h>
    #include <linux/syscalls.h>
    // ****************************************************************************
    // Inicializacion del modulo
    //   Funcion de registracion para el evento
    // ****************************************************************************
    static int __init hello(void)
    	printk(KERN_EMERG "Hello!!.\n");
      return 0;
    // ****************************************************************************
    // Desinicializacion del modulo
    //   Funcion para desregistracion del el evento
    // ****************************************************************************
    static void __exit bye(void)
    	printk(KERN_EMERG "Bye!!.\n");
    And a makefile
    # Makefile for the hello
    # Modify the path to the kernel sources
    ifneq ($(KERNELRELEASE),)
    obj-m := drvhello.o
    # Path to the kernel sources
    # Adapt the path to your system setup
    KDIR :=$(HOME)/dev/linux-
    # Current directory
    PWD  := $(shell pwd)
    	$(MAKE) -C $(KDIR) SUBDIRS=$(PWD) modules
    then run make.

    then insmod drvhello.ko

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts