From: Jarno Paananen <jpaana@s2.org>
To: linux-kernel@vger.kernel.org
Subject: How to avoid zombie kernel threads?
Date: 30 Jan 2002 06:06:50 +0200 [thread overview]
Message-ID: <m3hep4qy79.fsf@kalahari.s2.org> (raw)
Hi,
I'm coding a driver (can be found from
http://hardsid.sourceforge.net/ is someone is actually interested)
that uses a kernel thread to do the actual work asynchronously from
rest of the world. The thread is created when opening a character
device and exits when the device is closed.
This works fine otherwise but if the user mode process opens and
closes the device multiple times during its lifetime I get N-1
zombie kernel threads where N is the number of opens.
The code goes like this:
in device open:
DECLARE_MUTEX_LOCKED(sem);
int rmmod = 0;
rmmod = 0;
notify = &sem;
kernel_thread(hsid_thread, (void *)sid_data, 0);
down(&sem);
notify = NULL;
in device close:
notify = &sem;
rmmod = 1;
up(&todoSem); // just to wake the thread to do something
down(&sem);
notify = NULL;
rmmod = 0;
and the thread itself does:
[daemonize() etc.]
/* Notify the parent */
if(notify != NULL)
up(notify);
for(;;)
{
if (rmmod || signal_pending(current))
break;
/* We sit here waiting for something to do */
down_interruptible(&todoSem);
if (rmmod || signal_pending(current))
break;
[actual work]
}
if(notify != NULL)
up(notify);
return 0;
I think this worked fine in earlier 2.4 versions (not sure though),
but I'm now seeing this in both 2.4.18-pre7 and 2.5.2-dj6, UP and SMP.
Thanks,
// Jarno
next reply other threads:[~2002-01-30 4:07 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2002-01-30 4:06 Jarno Paananen [this message]
2002-01-30 4:34 ` John Levon
2002-01-30 4:34 ` Evgeniy Polyakov
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=m3hep4qy79.fsf@kalahari.s2.org \
--to=jpaana@s2.org \
--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®