I better be more clearer and show some code.. So this is the father starting his children :
#Start fork foreach my $xml_obj (@{$xml_ojects_ref}){ my $pid = fork(); if ($pid) { # parent push(@childs, $pid); $framework_child_procs{$pid} = 1; }elsif($pid == 0) { # child my $results = new testProcess($xml_obj,$fatherSN); #Test proce +ss is a new run exit 0; }else { print ,"couldnt fork: $!"; exit 1; } } #Wait for to end foreach my $child (@childs) { my $tmp = waitpid($child, 0); print "done with pid $tmp"; }
This is the code (inside the father class) , which handles the CTRL+C:
$SIG{INT}=\&ctrl_c_handler; sub ctrl_c_handler { $SIG{'INT'}='IGNORE'; my @procs = keys (%{fatherProcess::framework_child_procs}); kill SIGUSR1 => @procs; foreach my $child (@procs) { my $tmp = waitpid($child, 0); } }
This is a code inside a child (this is how I start the threads inside a child actually):
my $t = threads->new (sub{ local $SIG{'USR1'}=sub {threads->exit();}; \&$functions_name(@parameters); }); my $result = $t->join();
Now the signal (CTRL+C) comes from the user / CLI , then it catched by the father (going to ctrl_c_handler function) , and then ctrl_c_handler function suppose to send the USR1 signal to the threads - but the thread doesn't catch it. In addition - in the child (testProcess), before starting the thread , I have another USR1 handler , which caught - only after the thread is ending. I think your solution is not suitable here.. please help :)

In reply to Re^2: killing threads inside forks by mojo2405
in thread killing threads inside forks by mojo2405

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.