cristj1 has asked for the wisdom of the Perl Monks concerning the following question:
I'm pretty green and novice-like on PERL. I migrated a 10+ year old Perl script from Solaris 10 (!) to RHEL 7.3, Perl (v5.8.8) to (v5.16.3). It mostly runs great but I continue to have recurring problems with defunct processes. I've read tons of articles on threads, join, $SIG{CHLD} = 'IGNORE', etc. I basically understand I'm not reaping child processes correctly but am way over my head on how to correct it. I could take a week or two to bone up but I hope someone will have pity on this poor beggar and help me out.
The script kicks off a bunch of child processes. They do their thing and the main script SEEMs to try to clean up a bit by simply doing a "join" on each child. This worked fine on the old system. Now, it only seems to work OK when the number of children is small--say less than 50--but seems to result in defuncts when the "family" is much bigger than around 50.
Here are what I think are the salient bits of code. Can you help? I THINK I need to do a "wait" or a $SIG{CHLD} = 'IGNORE', but I don't know enough to just try things. Can you help? Here's where the kids get born:
... use threads; ... BEGIN { $Config{useithreads} or die "Recompile Perl with threads!"; } # end BEGIN ... switch($action) { case /adminpass(,|$)/ { print "Do adminpass ($hostname)\n" if($verbose || $debug); $t[++$#t]=threads->new(\&adminpass); next; } # end case /adminpass/ case /backup(,|$)/ { print "Do backup ($hostname)\n" if($verbose || $debug); $t[++$#t]=threads->new(\&backup); next; } # end case /backup/ case /buildhosts(,|$)/ { print "Do buildhosts ($hostname)\n" if($verbose || $debug); $t[++$#t]=threads->new(\&buildhosts); next; } # end case /buildhosts/ case /buildhostsdell(,|$)/ { print "Do buildhostsdell ($hostname)\n" if($verbose || $debug +); $t[++$#t]=threads->new(\&buildhostsdell); next; } # end case /buildhostsdell/ etc...
They do their thing in their respective subroutines, then the main thread does the following in efforts to clean up.
# Loop through all the threads my $thr; foreach $thr (threads->list) { # Don't join the main thread or ourselves if ($thr->tid && !threads::equal($thr, threads->self)) { $x=$thr->join; print 'TID ' . $thr->tid() . " returned: $x\n" if($verbose || $d +ebug); } # end if } # end foreach # Exit the script cleanly exit 0;
I REALLY appreciate your help!
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: defunct process are WAY beyond my experienc
by zentara (Cardinal) on Jul 03, 2017 at 16:05 UTC | |
|
Re: defunct process are WAY beyond my experienc
by huck (Prior) on Jul 03, 2017 at 17:49 UTC | |
|
Re: defunct process are WAY beyond my experienc
by huck (Prior) on Jul 03, 2017 at 17:17 UTC | |
| |
|
Re: defunct process are WAY beyond my experienc
by karlgoethebier (Abbot) on Jul 03, 2017 at 19:59 UTC | |
| A reply falls below the community's threshold of quality. You may see it by logging in. |