Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 19 Feb 2017 05:54:22 +0200
From:      Konstantin Belousov <kostikbel@gmail.com>
To:        Hans Petter Selasky <hps@selasky.org>
Cc:        FreeBSD Current <freebsd-current@freebsd.org>
Subject:   Re: First thread in proc in not passed to thread_dtor eventhandler upon exit
Message-ID:  <20170219035422.GQ2092@kib.kiev.ua>
In-Reply-To: <933e132d-289b-330d-b349-584a25e279d4@selasky.org>
References:  <933e132d-289b-330d-b349-584a25e279d4@selasky.org>

next in thread | previous in thread | raw e-mail | index | archive | help
On Sat, Feb 18, 2017 at 10:40:00PM +0100, Hans Petter Selasky wrote:
> Hi,
> 
> Is the following a bug or feature. I observe that the first thread in a 
> procedure is not passed to thread_dtor as declared by the following 
> eventhandler, when the procedure exits.
> 
> EVENTHANDLER_DECLARE(thread_dtor, thread_dtor_fn);
> 
> Is this a bug or feature?
This is a feature.  When a zombie process is reaped, the last thread in
the process (the one which exited it) is left in the process thread list.
This is an optimization, because process without at least one thread
is never useful.

You can see the code in fork1() which allocates struct proc from zone
and then checks if there any thread pre-allocated as well (both struct
proc and struct thread are type-stable).

Since the last thread is not freed, its destructor is not signalled.

> 
> I see a couple of clients in the kernel and if the first thread in proc 
> is simply recycled by re-init, we're leaking data for these clients?
> And I'm planning to add one more for the LinuxKPI.
> 
> Any insight?
> 
> --HPS
> _______________________________________________
> freebsd-current@freebsd.org mailing list
> https://lists.freebsd.org/mailman/listinfo/freebsd-current
> To unsubscribe, send any mail to "freebsd-current-unsubscribe@freebsd.org"



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20170219035422.GQ2092>