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!


In reply to defunct process are WAY beyond my experienc by cristj1

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.