SIGKILL and a sleeping kernel module

Silviu Popescu silviupopescu1990 at gmail.com
Tue Feb 19 04:11:01 EST 2013


On Tue, Feb 19, 2013 at 10:37 AM, Kevin Wilson <wkevils at gmail.com> wrote:

> Hi all,
> I am trying to send a SIGKILL to a kernel module which is sleeping.
> I added a printk after the sleep command.
> Sending a SIGLKILL (by kill -9 SIGLKILL pidOfKernelThread) does **not**
> yield the message from printk("calling do_exit\n");
>  which is immediately after the msleep() command, as I expected.
>
> Moreover, ps before and after the kill show 'D' in the STAT column
> (STATUS), which means that the process is sleeping (If I am not
> wrong).
>
> Any ideas why ?
> below is the code:
>
> #include<linux/init.h>
> #include<linux/module.h>
> #include<linux/kernel.h>
> #include<linux/kthread.h>
> #include<linux/sched.h>
> #include <linux/delay.h>
>
> struct task_struct *task;
>
> int thread_function(void *data)
> {
>     int exit_sig = SIGKILL;
>
>     allow_signal(SIGKILL);
>
>     printk("in %s\n",__func__);
>     // sleep for a second
>     msleep(60000);
>     printk("calling do_exit\n");
>     do_exit(exit_sig);
>
>     return 0;
> }
>
> static int kernel_init(void)
>     {
>     task = kthread_create(thread_function,NULL,"MY_KERNEL_THREAD");
>     return 0;
> }
>
> static void kernel_exit(void)
>     {
>     printk("in kernel_exit\n");
>     kthread_stop(task);
>     }
>
>
> module_init(kernel_init);
> module_exit(kernel_exit);
>
> MODULE_AUTHOR("Tester");
> MODULE_DESCRIPTION("test");
> MODULE_LICENSE("GPL");
>

Hello Kevin!

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.

Hope this helps a little.


[1] http://linux.die.net/man/1/ps

-- 
Silviu Popescu
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20130219/ca43f65f/attachment.html 


More information about the Kernelnewbies mailing list