in reply to How to pass CTRL-C to child script only

Untested

Did you set A to ignore and B to handle the signal? Please show some code, so that the monastery can help you find the problem.

Update: As stated below, you will probably need to, after forking, set the process group and/or pass along the signal from A to B.

--MidLifeXis

  • Comment on Re: How to pass CTRL-C to child script only

Replies are listed 'Best First'.
Re^2: How to pass CTRL-C to child script only
by ohmysea (Novice) on Aug 23, 2010 at 14:13 UTC
    Yes, I've tried that:

    Script A:
    $SIG{'INT'} = 'IGNORE';

    Script B:
    $SIG{'INT'} = sub { exit(0); };

    With this, CTRL-C has no effect on either script.
    Using die instead of exit has the same result.

    Also, script B is called from script A as follows:
    my $login = new CQLogin(); $login->autoLogon();
    autoLogon is a subroutine in script B (CQLogin)

    Thanks.
      In script A do:
      $SIG{INT} = sub { kill 2, $pid_of_scriptB;};

      Should work, not tested.

      This is still unclear, reason is, do you  fork in CQLogin? If you don't you're just  useing the module invoking a method on the instantiated object within the same process and the whole process will just terminate on Ctrl-C

        I'm just use ing the CQLogin module in script A, so in this case I cannot use kill as there is no separate PID for script B, is that correct?

        The thing is, in script B, CTRL-C will only ever be invoked during STDIN of subroutine autoLogon, so I tried to end script B during STDIN as follows:

        handler:
        my $stop = 0; $SIG{'INT'} = sub { $stop = 1 };
        during STDIN:
        print "->CQ username: "; while (<STDIN>){ if ($stop == 1){ return(0); } last; } chomp ($username = <STDIN>);
        the current problem with this is that, after pressing CTRL-C, the user will have to press the enter key again to exit script B. and if the user actually wants to pass in input, the input will need to be entered twice, but I guess I will have to work around this way for this problem.

        Thanks!