<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Tue, Feb 19, 2013 at 10:37 AM, 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:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Hi all,<br>
I am trying to send a SIGKILL to a kernel module which is sleeping.<br>
I added a printk after the sleep command.<br>
Sending a SIGLKILL (by kill -9 SIGLKILL pidOfKernelThread) does **not**<br>
yield the message from printk("calling do_exit\n");<br>
which is immediately after the msleep() command, as I expected.<br>
<br>
Moreover, ps before and after the kill show 'D' in the STAT column<br>
(STATUS), which means that the process is sleeping (If I am not<br>
wrong).<br>
<br>
Any ideas why ?<br>
below is the code:<br>
<br>
#include<linux/init.h><br>
#include<linux/module.h><br>
#include<linux/kernel.h><br>
#include<linux/kthread.h><br>
#include<linux/sched.h><br>
#include <linux/delay.h><br>
<br>
struct task_struct *task;<br>
<br>
int thread_function(void *data)<br>
{<br>
int exit_sig = SIGKILL;<br>
<br>
allow_signal(SIGKILL);<br>
<br>
printk("in %s\n",__func__);<br>
// sleep for a second<br>
msleep(60000);<br>
printk("calling do_exit\n");<br>
do_exit(exit_sig);<br>
<br>
return 0;<br>
}<br>
<br>
static int kernel_init(void)<br>
{<br>
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>
MODULE_AUTHOR("Tester");<br>
MODULE_DESCRIPTION("test");<br>
MODULE_LICENSE("GPL");<br></blockquote></div><br></div><div class="gmail_extra">Hello Kevin!<br><br></div><div class="gmail_extra">According to the man page of ps[1], the D state corresponds to an "Uninterruptible sleep (usually IO)". That means that signals (such as SIGKILL) will have no effect on the process. Your signal would have worked if the process was in the S state, which is interruptible sleep.<br>
<br></div><div class="gmail_extra">Hope this helps a little.<br></div><div class="gmail_extra"><br><br>[1] <a href="http://linux.die.net/man/1/ps">http://linux.die.net/man/1/ps</a><br clear="all"></div><div class="gmail_extra">
<br>-- <br>Silviu Popescu<br><br>
</div></div>