Find the answer to your Linux question:
Results 1 to 6 of 6
hi friends, Iam new to Kernel Programming. I just started by a basic example given in the book My Kernel Version is 2.6.24.2 and OS is Federo Core 9 example ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    May 2008
    Posts
    5

    Post kernel programming starter


    hi friends,

    Iam new to Kernel Programming.

    I just started by a basic example given in the book

    My Kernel Version is 2.6.24.2 and OS is Federo Core 9

    example program hello.c is
    //////////////////////////////////////////////////////

    #include <linux/module.h>
    #include <linux/kernel.h>
    int init_module(void)
    {
    printk("<1>Hello world 1.\n");
    return 0;
    }
    void cleanup_module(void)
    {
    printk(KERN_ALERT "Goodbye world 1.\n");
    }
    --------------------------------------------------

    makefile is

    obj−m += hello.o

    at command prompt i gave the command

    make -C /usr/src/linux-`uname -r` SUBDIRS=$PWD modules


    but the result is

    make: Entering directory `/usr/src/linux−2.6.24.2
    Building modules, stage 2.
    MODPROBE 0 modules
    make: Leaving directory `/usr/src/linux−2.6.24.2

    its not creating the corresponding .ko files

    plz help me where i have gone wrong

  2. #2
    Linux Newbie
    Join Date
    Mar 2008
    Location
    Hyderabad
    Posts
    109
    You forgot to add

    module_init(init_module);
    module_exit(cleanup_module);

    at end of the c file.

  3. #3
    Just Joined!
    Join Date
    May 2008
    Posts
    5
    i tried what u have told

    but still its giving the same output

  4. $spacer_open
    $spacer_close
  5. #4
    Linux Newbie
    Join Date
    Mar 2008
    Location
    Hyderabad
    Posts
    109
    Add
    MODULE_LICENSE("GPL");
    in your C file.

    Make a Makefile in the same directory with the content

    ifneq ($(KERNELRELEASE),)
    obj-m := hello.o
    else
    KERNELDIR ?= <Your Kernel path>
    PWD := $(shell pwd)
    default:
    $(MAKE) -C $(KERNELDIR) M=$(PWD) modules
    endif

    and use make command to compile.

  6. #5
    Just Joined!
    Join Date
    May 2008
    Posts
    5
    thanks vijay

    i got that . But inspite of giving the priority level as 1 . The output is getting

    written to /var/log/messages file instead of console.

  7. #6
    Linux Newbie
    Join Date
    Mar 2008
    Location
    Hyderabad
    Posts
    109
    If you are expecting the result on X terminal then you are wrong.
    Press Ctrl + Alt + F1 login and run thre program you will get your result.
    Cheers

Posting Permissions

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