Perl - a child process

I wrote the following code snippet to test the signaling between the child and parent. Ideally, when a child element provides a parent SIGINT element, the parent should return to a new iteration and wait for user input. This I observed in perl 5.8, but in perl 5.6.1 (which I requested 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;
        }
    }

}

Can anyone comment on this problem or in some other way notify the parent so that he enters a new iteration.

+3
source share
2 answers

5.6.X - , Perl , " " Perl 5.8.0. Perl, , , Perl 5.12 5.14.

+3

, , , SIGINT , . , fork() , , .

SIGINT fork(), , kill() .

( ):

$SIG{INT} = sub { die "GOTCHA" };

my $parent_pid = $$;
defined( my $pid = fork() ) or die "Cannot fork() - $!";

if($pid == 0)
{   
    print "child started\n";
    kill INT => $parent_pid;
}
else
{
    while(1)
    {
        eval
        {
            print "inside parent\n";
            <>;
        };
        if($@)
        {
            print "got the signal!!!!\n$@\n";
            next;
        }
    }
}
+2

All Articles