waitpid advice ? (killing off a kernel thread)

David Waite (mass@ufl.edu)
Sat, 19 Jun 1999 03:24:38 -0400 (EDT)


(not on list, please CC me)

I am working on the USB drivers trying to get the hub and the host
controller (uhci/ohci/ohci-hcd) drivers to unload correctly. The problem
is that the drivers have threads running that are not dying before I start
deallocating resources.

currently I am trying the following code (from hub.c):
=========begin code snip============
void cleanup_module(void)
{
if (khubd_pid >= 0)
{
int pid;
kill_proc(khubd_pid, SIGTERM, 1);
pid=waitpid(khubd_pid, NULL, __WCHILD);
if (pid!=khubd_pid)
printk("waitpid filed,"
"khubd_pid=%i,retpid=%i\n",khubd_pid,pid);
}
usb_deregister(&hub_driver);
}
=========end code snip============

Sometimes it works. Othertimes I get the waitpid filed (ok, so I typed
'failed' wrong...) message, promptly followed by a kernel oops.

The thread is created as follows...

=========begin code snip============
pid = kernel_thread(usb_hub_thread, NULL, CLONE_FS | CLONE_FILES |
CLONE_FILES | CLONE_SIGHAND);
if (pid >= 0) {
khubd_pid = pid;
return 0;
}

/* Fall through if kernel_thread failed */

--with the actual start of usb_hub_thread looking like

static int usb_hub_thread(void *__hub){
lock_kernel();
/*
static int usb_hub_thread(void *__hub){
lock_kernel();
/*
* This thread doesn't need any user-level access,
* so get rid of all our resources
*/
printk("usb_hub_thread at %p\n", &usb_hub_thread);
exit_mm(current);
exit_files(current);
exit_fs(current);
=========end code snip============

Anyways, my question is.. obviously my method of killing and then waiting
for the process to die is not working right. What can I do instead? Wait
queues do not seem to satisfy my needs, and I'm hesitant to look at
putting a 50 ms sleep in or something of the like.

can I just do a
while (wait_pid(pid,NULL,__WCLONE)==-1){wait_ms(10)};

and hope that eventually it exits?

-David Waite

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