LH2007 has asked for the wisdom of the Perl Monks concerning the following question:

This node falls below the community's minimum standard of quality and will not be displayed.
  • Comment on How to terminate a childprocess by press Ctrl_c

Replies are listed 'Best First'.
Re: How to terminate a childprocess by press Ctrl_c
by kyle (Abbot) on Oct 25, 2007 at 15:04 UTC

    It sounds as if you've got the basics already (though it's hard to tell).

    my $pid = fork(); die "Can't fork: $!" if ! defined $pid; if ( $pid ) { # parent $SIG{INT} = sub { warn "Sending sig INT to child PID $pid"; kill 'INT' => $pid; }; wait; } else { # child $SIG{INT} = sub { die "Caught sig INT" }; sleep 1 while 1; exit; }

    Note that without the signal handler in the child, it will still die when it gets the INT signal. I put it in the example just to make the signal visible.

    A reply falls below the community's threshold of quality. You may see it by logging in.