xaprb has asked for the wisdom of the Perl Monks concerning the following question:
I've written a program to dump MySQL data in parallel. Unfortunately it is behaving oddly. While two children are forked off running mysqldump shell commands, the parent just... hangs. It runs for a while, running waitpid() and forking off more children, but then sometimes it stops and does nothing anymore.
Without posting all the code, which is quite long, here's what I was able to isolate it to:
# Wait for the MySQL server to become responsive. my $tries = 0; while ( !$dbh->ping && $tries++ < $opts{w} ) { sleep(1); eval {
It hangs just after the ping and before the sleep(). I used DBI tracing to verify that it does call $dbh->ping. But it never gets past that.
So I commented this out. This is non-essential code: it's only there to handle the MySQL server going away and returning, in case there's a crash while you dump the data.
That moved the point of no return just a few lines down, to here:
# Start a new child process. while ( @work_to_do && $opts{m} > keys %kids ) { my $todo = shift @work_to_do;
Again, the hang is in the while() condition: it never reaches a 'print' placed just inside the loop. Meanwhile, top shows that the forked children go on to complete their work and exit, at which point they are defunct but never get reaped.
This is not the only forking program I've written. I'm not an expert at it, but I've never had anything like this happen before.
So my question is, do you have any general advice for me as I try to figure out the problem?
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: fork() and defunct children
by kyle (Abbot) on Feb 12, 2008 at 02:31 UTC | |
by Anonymous Monk on Feb 12, 2008 at 22:50 UTC | |
by kyle (Abbot) on Feb 13, 2008 at 03:19 UTC | |
Re: fork() and defunct children
by shmem (Chancellor) on Feb 11, 2008 at 20:45 UTC | |
Re: fork() and defunct children
by downer (Monk) on Feb 12, 2008 at 04:54 UTC | |
by Anonymous Monk on Feb 12, 2008 at 22:53 UTC |