in reply to •Re: Catching signals
in thread Catching signals

As I have replied to RMGir, i have tried making those corrections already and they don't seem to work. To clarify, here's the adapted code. I still don't see the handler message.
use strict; use sigtrap 'handler' => \&myhand, 'INT'; sub myhand{ print "\nOutta here $$!\n" }; my $pid = fork(); if ($pid) { print "I am parent $$\n"; for (1 .. 1000000){} kill INT => $pid; print "I am parent $$\n"; } elsif (defined($pid)) { print "I am child $$\n"; while (1){ sleep 1; } } else { print "child was not created\n"; } wait(); print "hi\n";

Replies are listed 'Best First'.
•Re: Re: •Re: Catching signals
by merlyn (Sage) on Sep 04, 2002 at 18:26 UTC
    Ahh. That code works as expected for me. The signal handler is called in both the parent and the child. I had to use a ^Z to finally get out of the code.

    So, what's your perl -V look like?

    -- Randal L. Schwartz, Perl hacker

      Please see 195144 for my answer and RMGir's reply. Is there any other work around to communicate between child and parent under win32? (this all started when a child was doing a blocking read and the parent was used to break out of that read cycle) So far, I have tried pipe $parent,$child or die, which still seemed to be blocked by that read statement. I also tried open(TO,"$-") || die but that's not supported by win32 either. I also tried threads, but activestate, in a stroke of genius, did not compile the perl.exe binary with 5005Threads, which makes the Thread.pm module useless. Instead, they compiled it with iThreads, which, even after getting threads.pm and threads::shared.pm into perl 5.6.1, do not seem to work for me (I get an error message saying that perl version is less than 5.8).

      Any other suggestions?

        Hi,

        I realize that this is not necessarily the answer to the question I was orignially asking, but it certainly is a solution to my problem (see the parent node). The problem was that I could not have a responsive Tk GUI running in parallel with a blocking socket read (Tk::fileevent under Win32 is broken - at least on perl 5.6.1 - I think it should be fixed by 5.7 or 5.8). Well, FYI, here's a hack that works.

        use IO::Socket; use IO::Select; use Tk; use strict; my $mw = MainWindow->new; my $text = $mw->Text->pack(); my $button = $mw->Button(-text=>"quit",-command=>sub{exit;})->pack; my $sock = IO::Socket::INET->new( Listen => 5, Reuse => 1, LocalPort => 7076, Proto => 'tcp', ) or die "Couldn't open socket: $!"; my $sel = IO::Select->new; $sel->add($sock); $mw->repeat(50 => \&read_sock); MainLoop; sub read_sock { my(@ready) = $sel->can_read(0); return if $#ready == -1; my $line; my $new_sock = $sock->accept(); $line = <$new_sock>; $text->insert('end',"$line\n"); }