Re: Killing kernel threads

Richard B. Johnson (root@chaos.analogic.com)
Tue, 19 Nov 2002 12:57:57 -0500 (EST)


On Tue, 19 Nov 2002, Super user wrote:

> Hi,
>
> Is there any guaranted way to kill kernel threads
> started from loadable modules. I've written a kernel
> module that starts 8 kernel threads and sometimes one
> of them goes into uninterruptible sleep. Is there
> anyway to flush away such threads while unloading
> modules.
>
> I've tried using kill_proc with SIGKILL but it doesn't
> seem to help.

#ifdef NEW_THREAD_EXIT
struct completion quit;
#else
struct semaphore quit;
#endif

In the kernel thread, someplace it can be awakened by a signal:

#ifdef NEW_THREAD_EXIT
complete_and_exit(&quit, 0);
#else
up_and_exit(&quit, 0);
#endif

In cleanup_module:

#ifdef NEW_THREAD_EXIT
wait_for_completion(&quit);
#else
down(&quit);
#endif

You define NEW_THREAD_EXIT based upon the kernel version. 2.4.18
uses the new syntax.

If you have a lot of threads, you need to have one of these constructs
for each of the threads and don't forget to initialize the semaphores.
Last I knew, this was the way to do it (and it works).

Cheers,
Dick Johnson
Penguin : Linux version 2.4.18 on an i686 machine (797.90 BogoMips).
Bush : The Fourth Reich of America

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/