Define alarm in threads

  • Thread starter Sébastien Cottalorda
  • Start date

S

Sébastien Cottalorda

I need to define an alarm like this.

eval {
my $thr = threads->new(\&run_cmd, params);
};
if ([email protected]){
print "[email protected]\n";
}
blah blah blah


sub run_cmd {
blah blah blah
threads->detach();
eval {
local $SIG{ALRM} = sub { die "TIMEOUT\n" };
alarm 10;
`$command_to_execute`;
alarm 0;
};
if ([email protected]){
print "[email protected]\n";
}
}

My problem is the following :
after waiting 10 seconds, either the master or the thread die.

How can I timeout the thread without affecting the master ?

Thanks in advance for any kind of help.

Sebastien
 
Ad

Advertisements


Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top