
mojo2405
New User
Jul 31, 2013, 7:46 AM
Post #2 of 2
(2216 views)
|
Re: [mojo2405] killing threads inside forks
[In reply to]
|
Can't Post
|
|
I better be more clearer and show some code.. So this is the father starting his children : <code> #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 process 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"; } </code> This is the code (inside the father class) , which handles the CTRL+C: <code> $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); } } </code> This is a code inside a child (this is how I start the threads inside a child actually): <code> my $t = threads->new (sub{ local $SIG{'USR1'}=sub {threads->exit();}; \&$functions_name(@parameters); }); my $result = $t->join(); </code> 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 :)
|