The script kicks off a bunch of child processes.

Hi, I think you are confusing defunct processes with threads. When using threads, the spawned threads can either be joined or detached. If you detach it, it dosn't need to be joined, it will cease when the code block ends. When the parent thread exits, it will take all child threads with it, and issue a warning that some child threads were running at exit.

As usual, you should should make a complete self-contained running example. Here are a few to show the difference between detach and join.:

#!/usr/bin/perl use strict; use warnings; use threads; foreach (0..100){ # create a thread to call the "run_system" subroutine # to run "ls -la" on the OS my $thread = threads->create("run_system", "ls -la"); $thread->detach; } sub run_system{ my $cmd = shift; system($cmd); } __END__ #1liner perl -Mthreads=async -le"async{ system 'dir'; } for 1 .. 100"
Joining is a bit different.
#!/usr/bin/perl use warnings; use strict; use threads; # join() does three things: it waits for a thread to exit, # cleans up after it, and returns any data the thread may # have produced. my $thr1 = threads->new(\&sub1); my $ReturnData1 = $thr1->join; print "Thread1 returned @$ReturnData1\n"; my $thr2 = threads->new(\&sub2); my $ReturnData2 = $thr2->join; print "Thread2 returned @$ReturnData2\n"; my $thr3 = threads->new(\&sub3); my $ReturnData3 = $thr3->join; print "Thread3 returned @$ReturnData3\n"; sub sub1 { print "In thread1.....\n"; sleep 5; my @values = ('1a','1b', '1c'); return \@values; } sub sub2 { print "In thread2.....\n"; sleep 5; my @values = ('2a','2b', '2c'); return \@values; } sub sub3 { print "In thread3.....\n"; sleep 5; my @values = ('3a','3b', '3c'); return \@values; }

I'm not really a human, but I play one on earth. ..... an animated JAPH

In reply to Re: defunct process are WAY beyond my experienc by zentara
in thread 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.