mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Andreas Dilger <adilger@turbolinux.com>
To: "Heusden, Folkert van" <f.v.heusden@ftr.nl>
Cc: "'Linux Kernel Development'" <linux-kernel@vger.kernel.org>
Subject: Re: fork in module?
Date: Wed, 1 Nov 2000 10:50:08 -0700 (MST)	[thread overview]
Message-ID: <200011011750.eA1Ho8s06277@webber.adilger.net> (raw)
In-Reply-To: <27525795B28BD311B28D00500481B7601623A0@ftrs1.intranet.FTR.NL> "from Heusden, Folkert van at Nov 1, 2000 02:51:38 pm"

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/

  reply	other threads:[~2000-11-01 17:50 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2000-11-01 13:51 Heusden, Folkert van
2000-11-01 17:50 ` Andreas Dilger [this message]
2000-11-01 23:00   ` Daniel Phillips
2000-11-01 17:42 Dunlap, Randy

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=200011011750.eA1Ho8s06277@webber.adilger.net \
    --to=adilger@turbolinux.com \
    --cc=f.v.heusden@ftr.nl \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®