Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
The script works fine to kill the ping until you uncomment the print. Then it will not accept the SIGINT until the ping has completed.$SIG{INT}=\&myhand; print "Parent pid = $$ \n"; $pid = open(CMD, "ping google.com -n 15 |"); print "Ping running... pid = $pid \n\n"; # uncommenting this line breaks ability to SIGINT #print <CMD>; # keep the script running; only the SIGINT will exit while (1){sleep 1}; sub myhand() { print "Parent $$ caught SIGINT.\n"; print "Parent $$ will KILL $pid.\n"; kill 9, $pid; exit(0); }
I seem to have the same problem if I use open(). If I use exec(), it looks like the ping command itself accepts the CTRL+C?#parent if ($forkpid = fork) { local $SIG{INT} = sub { print "i'm quitting"; kill 9, $pid; exit; }; waitpid($forkpid, 0); #child } else { die "cannot fork: $!" unless defined $forkpid; $SIG{INT} = sub { print "i'm quitting child"; close(CMD); kill 9, $p +id; exit; }; $pid = open(CMD, "ping google.com -n 15 |"); # exec ("ping google.com -n 15") or die "Can't exec: $!\n"; } print "Done with fork. Here are my results:"; print <CMD>;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: SIGINT and system calls
by Zaxo (Archbishop) on Jan 20, 2005 at 05:01 UTC | |
by Anonymous Monk on Jan 20, 2005 at 05:26 UTC | |
by Zaxo (Archbishop) on Jan 20, 2005 at 05:43 UTC | |
by Anonymous Monk on Jan 20, 2005 at 05:59 UTC | |
by Anonymous Monk on Jan 20, 2005 at 17:20 UTC |