LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Kernel Module Writing (https://www.linuxquestions.org/questions/programming-9/kernel-module-writing-588256/)

itz2000 09-29-2007 02:10 PM

Kernel Module Writing
 
How would you use sleep in a kernel module? would you suggest wait_event_interruptible()?
I want to use timed delays.


Code:


#include <linux/kernel.h>
#include <linux/init.h>
#include <linux/unistd.h>
#include <linux/module.h>
#include <linux/sched.h>


MODULE_DESCRIPTION("My kernel module");
MODULE_AUTHOR("Itzhak A. (itz2000+LKMPOST[@]gmail.com)");
MODULE_LICENSE("$LICENSE$");

static int c_proj_hello_module_init_module(void)
{
//sleep?
        return 0;
}

static void c_proj_hello_module_exit_module(void)
{
        printk( KERN_DEBUG "Module c_proj_hello_module exit\n" );
}

module_init(c_proj_hello_module_init_module);
module_exit(c_proj_hello_module_exit_module);


would give me :
Code:

root @ WhiteCastle ~ $ insmod /lib/modules/2.6.21.5-smp/kernel/drivers/misc/c_proj_hello_module-driver.ko
insmod: error inserting '/lib/modules/2.6.21.5-smp/kernel/drivers/misc/c_proj_hello_module-driver.ko': -1 Unknown symbol in module



Thanks for your help.

jiml8 09-29-2007 03:27 PM

You cannot sleep() in a kernel module. Take a look at wait_event_interruptible(). Also, if you want timed delays, take a look at setting/using timers and having them trigger interrupts to force a return from wait_event_interruptible().

itz2000 09-29-2007 05:04 PM

Quote:

Originally Posted by jiml8 (Post 2907794)
You cannot sleep() in a kernel module. Take a look at wait_event_interruptible(). Also, if you want timed delays, take a look at setting/using timers and having them trigger interrupts to force a return from wait_event_interruptible().

Manuals for kernel code needs improvement...

jiml8 09-29-2007 06:56 PM

google is your friend.

At least, it is for things like this.

itz2000 09-29-2007 10:36 PM

Thanks...

jiml8 09-29-2007 11:00 PM

When I googled for it I came up with pages of responses, including one for an online book about the Linux kernel, and a link to the online versions of the O'Reilly books about Linux device drivers. The O'Reilly book is the best resource, and it can be downloaded as HTML or as PDF. Don't have a link offhand, but it is out there.

itz2000 10-05-2007 03:54 PM

Quote:

Originally Posted by jiml8 (Post 2907996)
When I googled for it I came up with pages of responses, including one for an online book about the Linux kernel, and a link to the online versions of the O'Reilly books about Linux device drivers. The O'Reilly book is the best resource, and it can be downloaded as HTML or as PDF. Don't have a link offhand, but it is out there.

...


All times are GMT -5. The time now is 04:08 PM.