Re: fork in module?

From: Andreas Dilger (adilger@turbolinux.com)
Date: Wed Nov 01 2000 - 12:50:08 EST


You write:
> what would be the way of starting a sub-process in a module which then would
> run in the background? I guess plain fork() won't work?

We did this in one of our filesystem modules to have our own async cache
flush daemon. One thing you need to watch out for is that the new thread
is stopped before the module is unloaded. You can't simply increase the
module reference count, and decrease it when the thread exits, because
you are never allowed to remove a module with a non-zero refcount.

What you need to do is have your module cleanup function stop the thread,
and then wait to be sure it has exited before unloading. This is a
bit more tricky because you could send the thread a KILL signal and it is
still doing work or is rescheduled before it has completed exiting.

Check out obdfs/flushd.c (pupdated, obdfs_flushd_init, obdfs_flushd_cleanup)
and obdfs/super.c (init_module, init_obdfs, cleanup_module) at:

ftp://ftp.stelias.com/pub/obd/obd-0.004.tgz

This module also does slab-cache initialization and cleanup (properly!),
so that is also worth looking at.

Cheers, Andreas

-- 
Andreas Dilger  \ "If a man ate a pound of pasta and a pound of antipasto,
                 \  would they cancel out, leaving him still hungry?"
http://www-mddsp.enel.ucalgary.ca/People/adilger/               -- Dogbert
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
Please read the FAQ at http://www.tux.org/lkml/



This archive was generated by hypermail 2b29 : Tue Nov 07 2000 - 21:00:09 EST