> > Whoops, I spoke too soon, I think the sleep(3) causes the child not to
> > exit before the parent.  If instead I don't pass WNOHANG to the
> > waitpid command, it does error out.  So it looks like your theory is
> > correct, and I still have that problem.  I guess the only solution is
> > to rewrite the functions to use a new db connection every time?
> Each child should open its own database connection (if it needs one),
> and the parent should not keep the connection open at time of fork().

Yeah, that's what I ended up doing, and defining some global variables so
that I could re-use the previous functions I created, thanks for the help!

One other question I had, is pcntl_waitpid necessary in this case?  Passing
WNOHANG to it causes it to return immediately regardless of whether the
child has exited or not, and my previous test when I didn't use
pcntl_waitpid seemed to not leave any zombies as well.  Would it be fine
just to spawn off the child, and have the child exit at the end, and
continue on my merry way with the parent without checking the status of the

 As a more general question, I'm worried that if I just keep the script as
is, it's going to spawn off some crazy number of processes if I don't cap
it.  The first solution I came up with is to use a static variable in the
parent thread, and then sleep every 20 threads or so.  The most robust
solution would be to build logic into the calling function to actually check
for pids and only dispatch new threads when old ones had finished, but that
requires changing multiple places, while this can be localised to just the
dispatcher function.  Does the first solution I propose seem sane?


Reply via email to