How to manage a kernel thread?

=?ISO-8859-1?Q?I=F1aky_P=E9rez_Gonz=E1lez?= (inaky@peloncho.fis.ucm.es)
Sat, 4 Oct 1997 20:21:57 +0200


Hi

I've got a little problem I need some help to solve.

For the USB driver, there's an special part of the driver
which needs to act as a daemon. It could be done as a user level
daemon, which I consider to be a mess, as it would not have direct
access to the USB kernel structures, so I'd like to implement it as a
kernel thread, such as kswapd.

Surfing trough /usr/src/linux I see the start code for kswapd,
a call to kernel_thread() defined at asm/unistd.h. It contains an
scary warning which I'm not too able to interpret:

/*
* This is the mechanism for creating a new kernel thread.
*
* NOTE! Only a kernel-only process(ie the swapper or direct descendants
* who haven't done an "execve()") should use this: it will work within
* a system call from a "real" process, but the process memory space will
* not be free'd until both the parent and the child have exited.
*/

You see: the process I'll follow for the creation of this thread is
when the USB Driver Module is loaded, it initializes, registers hosts
and launches the hub driver daemon (aka: khubdd) to handle the device
plugin service and bus enumeration. Thus, I see it is not launched by
a kernel only process and then the proccess memory space won't be
freed until the parent and kid are over.

However, I don't know much about the internals of the module
loading stuff, so I do not what effects will this have. Could anybody
enlighten me?

Also I need to know if there's a way to terminate a kernel
thread (friendly, killing ...) and a way to attach to it to wait for
it's termination. I haven't been able of finding it if exists ...

Thanks in advance for your help!

Yep!

-- 

Linux-USB! http://peloncho.fis.ucm.es/~inaky/USB.html - - Inaky Perez Gonzalez -- PGP pubkey fingerprint - inaky@peloncho.fis.ucm.es -- 8E 34 3A 62 64 99 E2 44 - http://peloncho.fis.ucm.es/~inaky -- AD 7B 30 D9 DD FF 3E 4C - --------------------------------- -- ----------------------- - The loneliness of the long distance runner .....