jrsimmon has asked for the wisdom of the Perl Monks concerning the following question:

Monks- The following code works perfectly well on UNIX (5.005_03for PA-RISC2.0), but fails on Win32 (5.8.8 for MSWin32-x86-multi-thread). On Win32, the signal handler is never called. Any suggestions?
$SIG{INT} = sub {syswrite(STDERR, "$$:\tChild has signaled.\n", 27); }; $parent = $$; print "$$:\tI am the parent.\n"; unless($pid = fork){ print "$$:\tI am the child.\n"; print "$$:\tSending SIGINT to $parent.\n"; kill INT, $parent; exit; } print "$$:\tWaiting for the child to signal.\n"; print "." for(1..100); print "Did I catch it?";

Replies are listed 'Best First'.
Re: Win32 signals between parent/child
by TGI (Parson) on Aug 30, 2007 at 21:58 UTC

    kill doesn't work the same on win32. See the entry in perlport.


    TGI says moo

      Ok, that explains that. Is there a recommended alternative for simple parent/child communication? I had hoped to avoid using sockets, but I'm not seeing any other alternatives...

        As I pointed out above, the first problem with your OP code is that 'INT' is not defined anywhere, so your attempt to kill INT, $pid; is just a syntax error.

        Are you looking for a win32-only solution or must it be cross platform.


        Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
        "Science is about questioning the status quo. Questioning authority".
        In the absence of evidence, opinion is indistinguishable from prejudice.
Re: Win32 signals between parent/child
by BrowserUk (Patriarch) on Aug 30, 2007 at 22:54 UTC
Re: Win32 signals between parent/child
by suaveant (Parson) on Aug 30, 2007 at 18:25 UTC
    I can't actually say as I am not a windows programmer, but I can offer a possible alternative...

    If you have an application where your child is simply waiting you could use a socketpair instead of a signal. Not only is it probably safer it is much more robust, and allows to to send info back and forth between the two.

    Obviously it doesn't help when you want to interrupt something, but often that is not necessary.

                    - Ant
                    - Some of my best work - (1 2 3)