Re: OT: fork(): parent or child should run first?

Ian Campbell
2006-01-11T14:04:52Z

On Wed, 2006-01-11 at 14:55 +0100, Bernd Petrovitsch wrote:
> On Wed, 2006-01-11 at 13:49 +0000, Ian Campbell wrote:
> > On Wed, 2006-01-11 at 14:25 +0100, Bernd Petrovitsch wrote:
> > > Then this leaves the race if an old pid is reused in a newly created
> > > process before the last instances of that pid is cleaned up.
> >
> > The PID won't be available to be re-used until the signal handler has
> > called waitpid() on it?
>
> Yes.
> But ATM the signal handler calls waitpid() and stores the pid in a
> to-be-cleaned-pids array (at time X).
> The main loop at some time in the future (say at time X+N) walks through
> the to-be-cleaned-pids array and cleans them from the active-childs
> array.

yuk... I'd say the application is a bit dumb for calling waitpid before
it is actually prepared for the pid to be reclaimed.

A possible solution would be to also defer the waitpid until the main
loop cleanup function, perhaps flagging the entry in the child array as
not-active between the signal and that time or moving the pid from the
active to an inactive array in the signal handler.

Ian.
--
Ian Campbell
Current Noise: Sloth - Into The Sun

To err is human,
To purr feline.
-- Robert Byrne