|Think about Loose Coupling|
system() requires double ctrl-cby saintmike (Vicar)
|on Nov 10, 2008 at 07:25 UTC||Need Help??|
saintmike has asked for the wisdom of the Perl Monks concerning the following question:
I've always found it annoying that if you start a Perl program like
from the shell and you want to terminate it by using CTRL-C, you have to hit CTRL-C twice.
It gets worse if you run a loop like
then you have to hit CTRL-C ten times in a row to terminate the program!
You can easily reproduce this behavior by running
which requires two CTRL-C key strokes to terminate. On the other hand, if you use backquotes, as in
then one CTRL-C suffices. In both cases, both the perl program and the executed shell script are running in the same process group, so the shell will send SIGINT to both processes if you hit CTRL-C once.
However, in the system() case, perl performs some magic to block the SIGINT signal before it execs the child (pp_system in util.c):
So what happens is that the shell sends SIGINT to both parent and child, but perl choses to only terminate the child, while the parent keeps running.
Why is it doing that?