signal problem

C

C&J

Hi,
I have a cod as following :

....
my $stop = 0;
sub my_sigint_catcher {
$stop = 1;
};
$SIG{'INT'} = 'my_sigint_catcher';

while (1) {
....
system("ANOTHER PERL SCRIPT");
...
last if ($stop);
}
exit 0;


Here is my question:
1. The system(" ... ") has its own $SIC{'INT'} handler. Therefore, when I do ctrl-c during this period, the $stop never get set.
Is that possible to catch this ctl-c during system("...")'s execution?
2. I thought another easy to fix the problem is to use special combination dedicated for this, such as (F1 key, or CTRL-O).
How can I do this? or where can I find related tutorial?

Thanks
Chris
 
J

John W. Krahn

[ Please post using plain text -- NOT HTML. TIA ]

C&J wrote:

I have a cod as following :

Ok, I'll answer just for the halibut.

my $stop = 0;
sub my_sigint_catcher {
$stop = 1;
};
$SIG{'INT'} = 'my_sigint_catcher';

while (1) {
....
system("ANOTHER PERL SCRIPT");
...
last if ($stop);
}
exit 0;

Here is my question:
1. The system(" ... ") has its own $SIC{'INT'} handler. Therefore,
when I do ctrl-c during this period, the $stop never get set.
Is that possible to catch this ctl-c during system("...")'s
execution?

perldoc -q "How do I make a system\(\) exit on control\-C"

Found in /usr/lib/perl5/5.6.0/pod/perlfaq8.pod
How do I make a system() exit on control-C?

You can't. You need to imitate the system() call (see the
perlipc manpage for sample code) and then have a signal
handler for the INT signal that passes the signal on to
the subprocess. Or you can check for it:

$rc = system($cmd);
if ($rc & 127) { die "signal death" }

2. I thought another easy to fix the problem is to use special
combination dedicated for this, such as (F1 key, or CTRL-O).
How can I do this? or where can I find related tutorial?

perldoc Curses
perldoc Term::ReadLine



John
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,596
Members
45,143
Latest member
DewittMill
Top