SIGKILL and a sleeping kernel module

Srinivas Ganji srinivasganji.kernel at gmail.com
Wed Feb 20 01:29:56 EST 2013


On Tue, Feb 19, 2013 at 5:02 PM, Kevin Wilson <wkevils at gmail.com> wrote:

> Hi,
>
> Thanks about the info about ps.
> This raises two new questions:
> 1)  The following code is a very basic kernel module (based on my
> previous code, removing somethings).
> I do not understand something:
> I call
>   /* sleep for a millisecond */
>     msleep(1);
>     printk("calling do_exit\n");
>     msleep(60000);
>
> In my understanding, after 1 millisecond, it should have been
> available to the scheduler, and after returning to the line after
> msleep(1), it should print "calling do_exit". However,
> I see no such log message. Any ideas why ? can something be
> added to enable this ?
>
> 2)How can I create a kernel thread so that it will be in
> TASK_INTERRUPTIBLE state ? there must be a way,
> since I see many kernel threads where ps shows "S" in the
> status coumn.
>
>
> struct task_struct *task;
>
> int thread_function(void *data)
> {
>     int exit_sig = SIGKILL;
>
>     printk("in %s\n",__func__);
>     /* sleep for a millisecond */
>     msleep(1);
>     printk("calling do_exit\n");
>     msleep(60000);
>     do_exit(exit_sig);
>
>     return 0;
> }
>
> static int kernel_init(void)
>     {
>     printk("in kernel_init\n");
>     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);
>
>
> rgs
> Kevin
>
>
After creating the kernel thread, you can use wake_up_process(task) call
which will run your thread function.

Generally, when we create a kernel thread using kthread_create,


> _______________________________________________
> Kernelnewbies mailing list
> Kernelnewbies at kernelnewbies.org
> http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20130220/2c97dc9f/attachment-0001.html 


More information about the Kernelnewbies mailing list