<br><div class="gmail_quote">On Tue, Feb 19, 2013 at 5:02 PM, Kevin Wilson <span dir="ltr"><<a href="mailto:wkevils@gmail.com" target="_blank">wkevils@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Hi,<br>
<br>
Thanks about the info about ps.<br>
This raises two new questions:<br>
1) The following code is a very basic kernel module (based on my<br>
previous code, removing somethings).<br>
I do not understand something:<br>
I call<br>
/* sleep for a millisecond */<br>
msleep(1);<br>
<div class="im"> printk("calling do_exit\n");<br>
</div> msleep(60000);<br>
<br>
In my understanding, after 1 millisecond, it should have been<br>
available to the scheduler, and after returning to the line after<br>
msleep(1), it should print "calling do_exit". However,<br>
I see no such log message. Any ideas why ? can something be<br>
added to enable this ?<br>
<br>
2)How can I create a kernel thread so that it will be in<br>
TASK_INTERRUPTIBLE state ? there must be a way,<br>
since I see many kernel threads where ps shows "S" in the<br>
status coumn.<br>
<div class="im"><br>
<br>
struct task_struct *task;<br>
<br>
int thread_function(void *data)<br>
{<br>
int exit_sig = SIGKILL;<br>
<br>
</div><div class="im"> printk("in %s\n",__func__);<br>
</div> /* sleep for a millisecond */<br>
msleep(1);<br>
<div class="im"> printk("calling do_exit\n");<br>
</div> msleep(60000);<br>
<div class="im"> do_exit(exit_sig);<br>
<br>
return 0;<br>
}<br>
<br>
static int kernel_init(void)<br>
{<br>
</div> printk("in kernel_init\n");<br>
<div class="im"> task = kthread_create(thread_function,NULL,"MY_KERNEL_THREAD");<br>
return 0;<br>
}<br>
<br>
static void kernel_exit(void)<br>
{<br>
printk("in kernel_exit\n");<br>
kthread_stop(task);<br>
}<br>
<br>
<br>
module_init(kernel_init);<br>
module_exit(kernel_exit);<br>
<br>
<br>
</div>rgs<br>
<div class="HOEnZb"><div class="h5">Kevin<br>
<br></div></div></blockquote><div><br></div><div>After creating the kernel thread, you can use wake_up_process(task) call which will run your thread function.</div><div><br></div><div>Generally, when we create a kernel thread using kthread_create, </div>
<div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="HOEnZb"><div class="h5">
_______________________________________________<br>
Kernelnewbies mailing list<br>
<a href="mailto:Kernelnewbies@kernelnewbies.org">Kernelnewbies@kernelnewbies.org</a><br>
<a href="http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies" target="_blank">http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies</a><br>
</div></div></blockquote></div><br>