Feeds:
Posts
Comments

Posts Tagged ‘signals. win32’

Having had a couple of surprising experiences with third-party perl modules using signals on windows, I decided to test them to see how extensive support is. As mst points out, it is good to have confidence in your chosen platform.

Here is my test program.

#!/usr/bin/env perl

use 5.010;

use strict;
use warnings;

say '#', scalar(keys %SIG), ' signals';

my %skip = map { $_, 1 } qw(STOP TSTP TTIN TTOU);

foreach my $sig (sort keys %SIG) {
    next if (exists $skip{$sig});

    my $pid = fork();
    if (! $pid) {
        sleep 1;
        say "$sig failed!";
        exit 0;
    }

    say "Testing $sig (on $pid)";
    kill $sig, $pid;
    my $catch = wait();
    say "($sig) $catch exited...\n";
}

I fork a new process (presumably this is a pseudo-fork piggy-backing on a thread instead of a process in windows, but it is something people might write if they weren’t aiming at portability to windows), and then I try and send it a signal using kill. If the kill fails, then we get a message.

On Linux, this works pretty well as you would expect, signalling both from the parent and from within the child (suiciding?). A few signals unsurprisingly didn’t cause the child to abort: CHLD, CLD, CONT, FPE, NUM32, URG, WINCH and a few needed to be skipped. However, it was consistent from run to run.

The tests on Windows varied from run to run. The first run aborted on the first signal (SIGABRT appropriately enough).

jared@win32 $ ./signal-test.pl
#26 signals
Testing ABRT (on -3628)
Terminating on signal SIGABRT(22)

The next one ran through to SIGFPE.

jared@win32 $ ./tsig2.pl
#26 signals
Testing ABRT (on -268)
ABRT failed!
(ABRT) -268 exited...

Testing ALRM (on -1440)
ALRM failed!
(ALRM) -1440 exited...

Testing BREAK (on -2596)
BREAK failed!
(BREAK) -2596 exited...

Testing CLD (on -3464)
CLD failed!
(CLD) -3464 exited...

Testing CONT (on -2360)
CONT failed!
(CONT) -2360 exited...

Testing FPE (on -3508)
Terminating on signal SIGFPE(8)

And the third ran through to SIGBREAK.

jared@win32 $ ./tsig2.pl
#26 signals
Testing ABRT
ABRT failed!
(ABRT) -3548 exited...

Testing ALRM
ALRM failed!
(ALRM) -2800 exited...

Testing BREAK
Terminating on signal SIGBREAK(21)

*sigh*. Well, that is pretty disappointing. I had a bunch of other signal related tests I was thinking about doing but there seems little point. I always think of Perl as a fairly platform-agnostic wrapper around the underlying OS, but it looks like I was seriously mistaken.

Read Full Post »

Follow

Get every new post delivered to your Inbox.