Hi All, As far as I could understand from the going on discussion on kernel threads is that, we would create a kernel thread if we want something to be done even if our module goes to sleep or the control returns back from module to user space. Lets say, our user process calls a system call which further invokes a specific module code in kernel space, that module starts the kernel thread and then that kernel thread (a totally different entity and context from our module) calls the demonize() to detach itself from the user process which called the module. Once this has been done and our module control returns back to user space, there will still be a different context (kernel thread module created) in existence and can be scheduled when a call to schedule() will be made. I hope we can unload the module once the module has created the kernel thread, as that thread is no more associated to module. This is all what I understood from going on conversation. Following are few of my doubts: 1. Once the thread has been created by module or core kernel, and that thread detach itself from the process (which created it thru some module) or the core kernel. Who will make that thread die ...... or in other words, who will kill that thread? 2. Its almost related to first question. Is it compulsory to kill the thread which has been created by module? Lets say my driver created 2 kernel threads in init_module() function of my module, do I need to kill those threads in cleanup_module() function. Incase I don't kill while cleaning up the module, who will kill those kernel thread. As far as I think those kernel threads will remain there till the time we shutdown the system. Please correct me if I am wrong at any point. Regards, Gaurav -----Original Message----- From: kernelnewbies-bounce@nl.linux.org [mailto:kernelnewbies-bounce@nl.linux.org] On Behalf Of aksingh@hss.hns.com Sent: Wednesday, June 30, 2004 5:51 PM To: Anupam Kapoor Cc: Jan Hudec; Anandraj; kernelnewbies@nl.linux.org Subject: Re: kernel threads i think you would use kernel threads in driver when you want to do something in a process context, not in a syscall. >>>> wanting to do something in process context means that I would like to do something during which i might sleep ? regards Amit Anupam Kapoor <anupam.kapoor@gmail.com>@nl.linux.org on 06/30/2004 03:52:28 PM Sent by: kernelnewbies-bounce@nl.linux.org To: Amit Kumar Singh/HSS@HSS cc: Jan Hudec <bulb@ucw.cz>, Anandraj <arm@tataelxsi.co.in>, kernelnewbies@nl.linux.org Subject: Re: kernel threads On Wed, 30 Jun 2004 15:01:24 +0530, aksingh@hss.hns.com <aksingh@hss.hns.com> wrote: > > > so what are the differences between a kernel module and kernel threads they are _very_ different...to paraphrase from an old poem "a module is a module, a kernel_thread is a kernel_thread and never shall the twain meet !" i hope you meant, a 'kernel thread' and a 'userland process'. a kernel thread has no userspace context in it (as i said earlier, it's mm pointer is NULL etc.), they operate in kernel space _only_ ###### yes i meant userland process ############# > , as > you said kernel threads can be scheduled, pre-empted and all.that is one > Whats the utility of kernel threads, do drivers generally use them or if I > put it in a better way, when should someone think of using kernel threads > in his/her modules? i think you would use kernel threads in driver when you want to do something in a process context, not in a syscall. there must be bunch of kernel threads running on your system. for me, i have things like: #### wanting to do something in process context means that I would like to do something during which i might sleep ? ## pdflushd : responsible for writing dirty pages to disk. earlier this was done via the bdflush and kupdated. ksoftirqd: helps processing of softirqs to name a few. kind regards anupam > > thanks > Amit > > Anupam Kapoor <anupam.kapoor@gmail.com> on 06/30/2004 02:55:43 PM > > To: Jan Hudec <bulb@ucw.cz> > cc: Amit Kumar Singh/HSS@HSS, Anandraj <arm@tataelxsi.co.in>, > kernelnewbies@nl.linux.org > > Subject: Re: kernel threads > > > > > also, kernel threads have their mm pointer set to NULL. kernel threads > are schedulable, preemptible etc. just like normal processes. > > anupam > > On Wed, 30 Jun 2004 10:55:40 +0200, Jan Hudec <bulb@ucw.cz> wrote: > > On Wed, Jun 30, 2004 at 13:15:23 +0530, aksingh@hss.hns.com wrote: > > > i read that already, there the programmer has used his own functions to > > > create threads and all, i just wanted to know if kernel threads are > > > standard features and if kernel provides some functions to create, > destroy > > > them, because I never came across them in linux till now. I dont think > > > drivers create different threads, correct ? > > > > Kernel threads are created, surprisingly, with a function > > kernel_thread(). Then they need to call daemonize() to fully get rid of > > their userland and reparent to init, because they are created by cloning > > whatever process happens to be current. > > > > > ------------------------------------------------------------------------ ------- > > > Jan 'Bulb' Hudec > <bulb@ucw.cz> > > > > > > > > -- Kernelnewbies: Help each other learn about the Linux kernel. Archive: http://mail.nl.linux.org/kernelnewbies/ FAQ: http://kernelnewbies.org/faq/ -- Kernelnewbies: Help each other learn about the Linux kernel. Archive: http://mail.nl.linux.org/kernelnewbies/ FAQ: http://kernelnewbies.org/faq/ -- Kernelnewbies: Help each other learn about the Linux kernel. Archive: http://mail.nl.linux.org/kernelnewbies/ FAQ: http://kernelnewbies.org/faq/