LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software > Linux - Kernel
User Name
Password
Linux - Kernel This forum is for all discussion relating to the Linux kernel.

Notices

Reply
 
Search this Thread
Old 04-19-2012, 02:21 AM   #1
karan2386
Member
 
Registered: Jan 2012
Posts: 34

Rep: Reputation: Disabled
running infinite loop in kernel module


I have make a module in which i would like to run an infinite loop till I don't unload the module . Presently if I do rmmod it gives me notice that module is still busy and after some time kernel panics.

while(1)
{
.......

}

Is there any trick through which I could run infinite loop till I unload the module.
 
Old 04-19-2012, 02:27 AM   #2
pan64
Senior Member
 
Registered: Mar 2012
Location: Hungary
Distribution: debian i686 (solaris)
Posts: 4,752

Rep: Reputation: 1271Reputation: 1271Reputation: 1271Reputation: 1271Reputation: 1271Reputation: 1271Reputation: 1271Reputation: 1271Reputation: 1271
I think you need to exit this loop before unloading
 
Old 04-19-2012, 02:33 AM   #3
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 12,277

Rep: Reputation: 1028Reputation: 1028Reputation: 1028Reputation: 1028Reputation: 1028Reputation: 1028Reputation: 1028Reputation: 1028
More likely you need to rethink your design.
 
Old 04-19-2012, 08:29 AM   #4
sundialsvcs
Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 5,377

Rep: Reputation: 1108Reputation: 1108Reputation: 1108Reputation: 1108Reputation: 1108Reputation: 1108Reputation: 1108Reputation: 1108Reputation: 1108
Quote:
Originally Posted by syg00 View Post
More likely you need to rethink your design.
Indeed, you do.

If a piece of software is designed to run as a loadable (and therefore, also unloadable) module, then by definition it is not "endless." It runs in response to some set of stimuli ... both those coming from whatever it's supposed to be responding-to and doing, and those that signal that the module is being unloaded. When that indication is received, the module must quickly terminate its affairs in an orderly fashion (or indicate that it refuses to be unloaded at this time). Existing source-code for USB drivers is an excellent source of reference here. (Never bother to "re-invent the wheel of knowledge" when writing kernel code: there's an abundance of tested source-code at your fingertips, to copy from, adapt and use.)

Let me please stress this point: Find something of known-good quality that already exists and copy its basic design faithfully. (For example, IIRC there is a "generic USB driver template" out there someplace.) Refer to the current source-code libraries of the Linux that you are actually targeting, not merely to books, because the internal implementation of Linux has evolved considerably over time. "Use the Source, Luke!"

Last edited by sundialsvcs; 04-20-2012 at 07:55 AM.
 
Old 04-19-2012, 11:22 PM   #5
bsat
Member
 
Registered: Feb 2009
Posts: 347

Rep: Reputation: 72
A module once loaded is always available for any function it is designed for. I don't see a reason why would you want an infinite loop in it.
And as pointed out above you can not remove module if it is running infinitely.
 
Old 04-20-2012, 08:26 AM   #6
cladisch
Member
 
Registered: Oct 2008
Location: Earth
Distribution: Slackware
Posts: 227

Rep: Reputation: 54
Make sure that the module initialization function returns, by starting a separate thread for the loop.
In the module exit function, tell the thread to stop, and wait until it has exited.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
[SOLVED] infinite loop that isnt infinite? frieza Programming 2 10-27-2010 02:16 PM
Running 2 infinite loop scripts at startup cricri Linux - Server 19 08-24-2009 04:42 PM
Kernel 2.6.20-1.2933.fc6, infinite loop eats CPU cycles? PTrenholme Fedora 2 03-31-2007 04:21 PM
Infinite Loop ewt3y Programming 3 08-16-2005 09:48 AM
infinite loop beginner_84 Programming 5 08-15-2004 02:32 AM


All times are GMT -5. The time now is 01:22 AM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration