Re: killing a kernel thread with SIGKILL

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 10/5/07, Mohammad M Molla <merajul_i@xxxxxxxxx> wrote:
>
>  kill_proc(kthread->thread->pid, SIGKILL, 1);
>

The above is one way of sending a SIGKILL signal - from within the kernel.

> I am trying to kill the thread by sending signal from userspace with "kill
> -p <pid>"

But your way above is from userspace, and therefore it needs a
userspace context to start with.

As I read the implementation of daemonize() (kernel/exit.c):

void daemonize(const char *name, ...)
{
         /*
         * If we were started as result of loading a module, close all of the
         * user space pages.  We don't need them, and if we didn't close them
         * they would be locked into memory.
         */
        exit_mm(current);
So it seems that the above completely removed all the userspace stuff
associated with the current kernel module....but wait....

        reparent_to_kthreadd();
}

kthreadd?   So this means that the current kernel module should have a
userspace context of kthreadd to run.   In my FC7, "ps -ef" will list
a kernel thread named as "kthreadd".   So I therefore conclude that
your way of sending a signal should be:

kill -9 PID where PID is the PID of the kthreadd process listed in "ps -ef"?

So if after daemonize(), the userspace becomes kthreadd.   But
becoming kthreadd also set all signals to be ignored, as shown below.

First the kthreadd kernel thread is created in rest_init() using
kthread_create(kthreadd()...) API.

And then looking into how kthreadd() is written?

kernel/kthread.c:

int kthreadd(void *unused)
{
        struct task_struct *tsk = current;

        /* Setup a clean context for our children to inherit. */
        set_task_comm(tsk, "kthreadd");
        ignore_signals(tsk);

>From above we can see that kthreadd() called ignore_signals():

And inside the kthreadd():

int kthreadd(void *unused)
{
        struct task_struct *tsk = current;

        /* Setup a clean context for our children to inherit. */
        set_task_comm(tsk, "kthreadd");
        ignore_signals(tsk);

And ignore_signal() will set ALL signal filter to SIG_IGN, including SIGKILL.

--
To unsubscribe from this list: send an email with
"unsubscribe kernelnewbies" to ecartis@xxxxxxxxxxxx
Please read the FAQ at http://kernelnewbies.org/FAQ


[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux