Find the answer to your Linux question:
Results 1 to 4 of 4
Hope someone can help... Have very strange problem... Basically I have a very simple "hello world" kernel module. file is Code: #include <linux/init.h> #include <linux/module.h> #include <linux/kernel.h> MODULE_DESCRIPTION("MyKernelMod"); MODULE_AUTHOR("Me"); MODULE_LICENSE("GPL"); ...
  1. #1
    Just Joined!
    Join Date
    Jul 2007
    Posts
    2

    problem with kernel module

    Hope someone can help...

    Have very strange problem...
    Basically I have a very simple "hello world" kernel module.
    file is

    Code:
    #include <linux/init.h>
    #include <linux/module.h>
    #include <linux/kernel.h>
    
    MODULE_DESCRIPTION("MyKernelMod");
    MODULE_AUTHOR("Me");
    MODULE_LICENSE("GPL");
    
    static int initMyModule(void) {
       printk("Loading MyModule\n");
       return 0;
    }
    
    static void closeMyModule(void) {
       printk("Closing MyModule\n");
    }
    
    module_init(initMyModule);
    module_exit(closeMyModule);
    I build it through the "make -C <kernel_src> -M=$(PWD) modules"

    the insmod the module.

    But the init doesn't work - I don't see in /proc/kmsg, console or syslog
    "Loading MyModule" but rmmod does!!!

    Any ideas where to begin to look?

    TIA
    RikD

  2. #2
    Linux Enthusiast
    Join Date
    Aug 2006
    Posts
    631
    You can check if your module is loaded, with (assuming your module name is hello.ko):

    Code:
    lsmod | grep hello
    Regards

  3. #3
    Just Joined!
    Join Date
    Jul 2007
    Posts
    2
    Module appears to load
    lsmod shows the module is there.

    But am curious as to why the initMyModule() code hasn't been executed, or what would make the system skip it?

  4. #4
    Linux Enthusiast
    Join Date
    Aug 2006
    Posts
    631
    You haven't specify a priority in your printk() statement, try (without a comma between the priority and the message):

    Code:
    printk(KERN_INFO "Loading MyModule\n");
    and:
    Code:
    printk(KERN_INFO "Closing MyModule\n");
    You can find the priorities in "kernel.h".

    Regards

Posting Permissions

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