【发布时间】:2013-07-30 16:30:12
【问题描述】:
我的 perl 脚本中有以下代码,但似乎无法正常工作:
my $thr;
sub start__server_thread()
{
$thr = threads->create(\&iperf_start_server, $_[0], $_[1], $_[2]);
print("Value of thread is $thr\n");
&START_SERVER_RESPONSE($controller_ip, $controller_port, "success", 2345, $_[1]);
}
sub iperf_start_server()
{
# Do some stuff here and then handle the signal
$SIG{'SIGSTOP'} = sub {
print("Stop signal received\n");
$thr->exit();
$flag = 1;
};
}
sub stop_server()
{
my ($dat,$filelog,$result);
$thr->kill('STOP');
$flag = 1;
sleep(10);
$thr->exit(1);
}
当从其他上下文调用 stop_server() 时,它会尝试向线程发送 SIGSTOP 信号。此时执行停止,我收到错误“收到信号 SIGSTOP,但在 perl 脚本中没有设置信号处理程序。我哪里出错了?
【问题讨论】:
-
Don't use prototypes -- 将 Perl 的 subs 声明为
sub name { ... }而不是sub name() { ... }。 -
你在什么平台上运行这个?我认为您的问题是您无法捕获
STOP或KILL信号。 -
我正在Linux上尝试上面的代码
标签: multithreading perl signals