perl-子进程发信号通知父进程 [英] perl - child process signaling parent

查看:75
本文介绍了perl-子进程发信号通知父进程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我编写了以下代码来测试子代与父代之间的信令.理想情况下,当孩子将SIGINT提供给父母时,父母应在新的迭代中返回并等待用户输入.我在perl 5.8中观察到了这一点,但是在perl 5.6.1(要求使用)中,父级实际上是被杀死"的.没有下一个迭代.

I have written the following piece of code to test signaling between child and parent. Ideally, when the child gives a SIGINT to parent the parent should come back in the new iteration and wait for user input. This I have observed in perl 5.8, but in perl 5.6.1(which I am asked to use) the parent is actually "killed". There is no next iteration.

my $parent_pid = $$;
$pid = fork();
if($pid == 0)
{   
    print "child started\n";
    kill 2, $parent_pid;
}
else
{
    while(1)
    {
        eval
        {
            $SIG{INT} = sub{die "GOTCHA";};
            print 'inside parent'."\n";
            $a = <>;
        };
        if($@)
        {
                print "got the signal!!!!\n$@\n";
                next;
        }
    }

}

请有人提供解决此问题的方法,或以其他方式向父级发送信号,使其进入新的迭代.

Could someone please give a walkaround for this problem or some other way to signal the parent so that it enters the new iteration.

推荐答案

5.6.X上的失败可能是由于Perl用来处理信号的方式所致,而该方式已通过.在这两种情况下,您都使用了实际上是考古的Perl,并且应该向您的主人强烈建议您至少应使用Perl 5.12,理想情况下应使用5.14.

The failure on 5.6.X might be because of the way Perl used to handle signals, which was fixed with 'Safe Signal Handling' in Perl 5.8.0. In either case, you are using a Perl which is practically archaeological and you should argue strongly to your masters that you should be using at least Perl 5.12, and ideally 5.14.

这篇关于perl-子进程发信号通知父进程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆