LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 01-04-2005, 03:45 AM   #1
b123coder
Member
 
Registered: Nov 2004
Location: india
Distribution: Fedora core 1
Posts: 67

Rep: Reputation: 15
how to sleep /create interval in kernel module?


hello all,
I require a schedule_timeout function statement to have kernel module sleep for 5 minutes. I require to call a function from kernel module from interval of 5 minutes.
For that i have written simple kernel module that should print string in function and that function be called in a interval of 1 minute but its printing continually without sleeping.

regards,
parag.


#define MODULE
#define __KERNEL__
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/init.h>
#include <linux/sched.h>
void reader()
{
char *buffer1="Timeout";
printk(KERN_DEBUG "buffer in file_reader is =%s\n",buffer1);
}

int init_module (void)
{
int i=0;
while(i<5)
{
reader();
schedule_timeout(6000);
i++;
}
return 0;
}

void cleanup_module(void)
{
printk(KERN_DEBUG "GoodBye Kernel\n");
}
MODULE_LICENSE("GPL");
 
Old 01-04-2005, 08:08 AM   #2
laceupboots
Member
 
Registered: Dec 2003
Location: Houston
Distribution: Knoppix,lenova yoga 3, Samsung s6 -android
Posts: 307

Rep: Reputation: 30
I don't know the answer to your question, but you might find some answers at this site.
http://www.koders.com/
My best guess would be your return statement.
 
Old 01-04-2005, 09:59 AM   #3
shishir
Member
 
Registered: Jul 2003
Location: bangalore . india
Distribution: openSUSE 10.3
Posts: 251

Rep: Reputation: 33
i think you have to take care that the task is marked in TASK_INTERRUPTIBLE sleep before you call schedule_timeout (set_curent_state(TASK_INTERRUPTIBLE))
..this is putting the module to sleep and if you see the pid it will basically be that of the insmod process...
so you have to put it to some state where it can sleep..cos when you are inserting the module the task state is running..and hence it continues to be in the running state..even when the shcedule_timeour is called as all it does is run a timer for you ..and then on that timers expiry schedule you in and make yours the running process on the cpu..

Last edited by shishir; 01-04-2005 at 10:37 AM.
 
Old 01-04-2005, 10:37 AM   #4
shishir
Member
 
Registered: Jul 2003
Location: bangalore . india
Distribution: openSUSE 10.3
Posts: 251

Rep: Reputation: 33
nice site laceupboots
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[Error] Kernel Module : No kernel module build environment saman007uk Debian 7 09-09-2006 06:34 PM
Searching for Server (BOOTP/DHCP) <sleep> <sleep> .. .. Eileen Linux - Networking 12 10-21-2005 01:14 AM
hid interval patch some Linux - Newbie 5 12-04-2003 06:28 AM
kernel module ignorant newbie looking for any one with kernel module knowledge cpoet Slackware 4 11-24-2003 09:37 PM
Programmable Interval Timers saintt Linux - General 0 10-19-2001 08:50 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 03:31 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration