Early in the routine that constitutes the child, do the following:
exit_files(current) ; /* close all files */
exit_mm(current) ; /* detach user pages */
current->pgrp = 1 ; /* detach from parent */
current->session = 1 ; /* now owned by "init" */
current->uid = 0 ; /* become root */
current->euid = 0 ; /* become root */
current->tty = NULL ; /* detach from any tty */
current->mm->arg_start = current->mm->arg_end = 0;
strcpy(current->comm, "MyProc") ; /* set my display name (short string) */
Make sure the string "MyProc" is fairly short. This will be the display name
of your process in a ps. It will be enclosed in ()'s.
Have the parent remember the process id somewhere in your driver.
Then when you want to kill off your process do this (assume process id is in
if (my_pid > 0) /* Only stop the kernel thread if running */
kill_proc(my_pid, SIGINT, 1) ;
Make sure that any waits that you do in the process are interruptible.
> I'm writing a module (for 2.2) which starts a kernel thread at insmod time.
> I have run into two problems. The first is that my thread is a child of
> insmod unless I start it from outside process context. Currently I work
> around that by launching it from a kernel timer which expires momentarily
> after insmod. The other problem is that when my thread functions exits, it
> becomes a zombie. Is there a way for me to cleanly remove the thread at
> rmmod time when it is finished doing it's work?
> Software Engineer, WGT Inc. . http://www.terran.org/~bryan