Re: Kthread kill

From: Julian Elischer <julian_at_elischer.org>
Date: Tue, 09 Sep 2008 09:03:43 -0700
kr Lekha wrote:
> Hi all,
> thanks very much for your valuable inputs.
> 
> I found out the way to exit the thread.
> Problem was psignal(p, SIGKILL); , the p->p_siglist was being reset after
> propagating this signal to threads associated with this proc.
> Hence i could poll once in a way if any unhandled signals
> were in curthread->td_siglist.
> 
> I am not sure if this is the optimal solution.
> Please do sugest if you have a better solution
> 
> 
> Why cant we have signal handlers for kernel threads? when i tried to
> register one, sigaction returned value 14 and signal handler didnt get
> registered.
> Thanks,
> lekha
> 
certain things do not work for kernel threads. signals is one of them
The definition of signals is very specific about what it does and it
is very clear that they can not work in user space.

kernels entities can send each other information in  many ways.
from direc scheduling (e.g. wakeup()) to sharing variables, to 
semaphores and mutexes. (and many more).

why do you think you want signals?


firstly are you using a kernel thtread or a kernel process?
(man kproc) (man kthread)

you should used kthread_suspend_check() when your thread has no work 
to do. And control it using kthread_resume() and kthread_suspend().

to make it shutdown simply set a variable  that it knows about and
resume it.. then it can check the variable and suicide.

if you want to signal it from user space there are many ways, from 
making a small pseudo device in /dev, to attempting to unload the
module, to addign your own provate syscall, to openning a unix domain 
socket. to it.



> 
> 
> 
> 
> 
> 
> On Mon, Sep 8, 2008 at 10:26 PM, John Baldwin <jhb_at_freebsd.org> wrote:
> 
>> On Wednesday 03 September 2008 05:32:00 am kr Lekha wrote:
>>> Hi,
>>> i wanted to kill a kthread created by my module, There is no actual
>>> kthread_kill to kill it
>>>
>>> hence I tried to send kill signal to thread
>>>  psignal(p, SIGTERM);
>>> psignal(p, SIGKILL);
>>> killproc(p,"messeage");
>>> and kthread_suspend()
>>>
>>> Nothing seems to be killing the kthread, I still see it
>>> [root_at_ /usr/src]# ps awx -l | grep kernel
>>>  UID   PID    PPID CPU PRI NI   VSZ   RSS MWCHAN STAT  TT       TIME
>>> COMMAND 0     1048     1      0     20   0     0       8      ktsusp
>>> DL ??     0:00.01 [new_kernel_thread]
>>>
>>>
>>> I have noticed that generally if kernel module wanted to kill a thread
>> then
>>> it calls
>>> {
>>>    wakeup(p);
>>>    msleep(p,0); /*or tsleep*/
>>> }
>>>
>>> This puts the thread to sleep forever. However kthread_suspend also
>>> performs same actions.
>> Your kthread has to explicitly check for a kill request in its main loop
>> and
>> call kthread_exit() or some such.  There is no force-kill for kthreads.
>>
>> --
>> John Baldwin
>>
> _______________________________________________
> freebsd-current_at_freebsd.org mailing list
> http://lists.freebsd.org/mailman/listinfo/freebsd-current
> To unsubscribe, send any mail to "freebsd-current-unsubscribe_at_freebsd.org"
Received on Tue Sep 09 2008 - 14:03:37 UTC

This archive was generated by hypermail 2.4.0 : Wed May 19 2021 - 11:39:35 UTC