mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* How to avoid zombie kernel threads?
@ 2002-01-30  4:06 Jarno Paananen
  2002-01-30  4:34 ` John Levon
  2002-01-30  4:34 ` Evgeniy Polyakov
  0 siblings, 2 replies; 3+ messages in thread
From: Jarno Paananen @ 2002-01-30  4:06 UTC (permalink / raw)
  To: linux-kernel

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

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: How to avoid zombie kernel threads?
  2002-01-30  4:06 How to avoid zombie kernel threads? Jarno Paananen
@ 2002-01-30  4:34 ` John Levon
  2002-01-30  4:34 ` Evgeniy Polyakov
  1 sibling, 0 replies; 3+ messages in thread
From: John Levon @ 2002-01-30  4:34 UTC (permalink / raw)
  To: linux-kernel; +Cc: jpaana

On Wed, Jan 30, 2002 at 06:06:50AM +0200, Jarno Paananen wrote:

> 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.

read frey's guide and look at some real code to see how to do this.

Think you are missing a reparent_to_init(). I don't know if bleeding
2.5 includes this in daemonize() yet.

You should really have asked this on kernelnewbies mailing list btw

http://www.kernelnewbies.org/

regards
john

-- 
"In no sense is [in]stability a reason to move to a new version. It's never a
reason."
	- Bill Gates

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: How to avoid zombie kernel threads?
  2002-01-30  4:06 How to avoid zombie kernel threads? Jarno Paananen
  2002-01-30  4:34 ` John Levon
@ 2002-01-30  4:34 ` Evgeniy Polyakov
  1 sibling, 0 replies; 3+ messages in thread
From: Evgeniy Polyakov @ 2002-01-30  4:34 UTC (permalink / raw)
  To: Jarno Paananen; +Cc: linux-kernel

On 30 Jan 2002 06:06:50 +0200
Jarno Paananen <jpaana@s2.org> wrote:

> Hi,

Good time of day.

> 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.

Maybe you should use do_exit() at the end or complete_and_exit()?

> [daemonize() etc.]
...
      do_exit(0); // At least usb hub do it in such manner.
>     return 0;


> Thanks,

I hope this will help you.

> // Jarno
> -

	Evgeniy Polyakov ( s0mbre ).

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2002-01-30  4:35 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-01-30  4:06 How to avoid zombie kernel threads? Jarno Paananen
2002-01-30  4:34 ` John Levon
2002-01-30  4:34 ` Evgeniy Polyakov

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®