develooper Front page | perl.perl5.porters | Postings from April 2007

Re: [PATCH] Fix kill(0, $pid) on Windows

Thread Previous | Thread Next
From:
Garrett Cooper
Date:
April 17, 2007 08:19
Subject:
Re: [PATCH] Fix kill(0, $pid) on Windows
Message ID:
4624E589.9020602@u.washington.edu
Steve Hay wrote:
> Steve Hay wrote:
>> Jan Dubois wrote:
>>> I broke the kill(0, $pid) behavior on Windows with change 29605
>>> (the one implementing killpg()):
>>>
>>>     http://public.activestate.com/cgi-bin/perlbrowse/p/29605
>>>
>>> The problem is that OpenProcess() returns a HANDLE, but on error it
>>> returns NULL and not the usual INVALID_HANDLE_VALUE. I assume the reason
>>> for this is that at the kernel level, the INVALID_HANDLE_VALUE bit
>>> pattern is the same as the pseudo handle for the current process.
>>>
>>> The attached patch restores kill(0, $pid) behavior.
>>
>> Good catch! I guess there really ought to be a test for this 
>> behaviour. I'll have a look later if nobody else beats me to it.
> 
> I had a quick go at it. How does the attached t/op/kill.t look?
> 
> Picking a PID that you know exists is easy, but how do you pick a PID 
> that you know doesn't exist? PID 0 currently doesn't exist on my (WinXP) 
> system, and it probably never does, but I've no idea how portable that 
> might be.
> 
> Also, are there any OSs that don't support kill(0, $pid) and therefore 
> need the tests skipping? perlport only mentions RISC OS so perhaps a 
> check for $^O eq 'riscos' will suffice?
> 
> 
> ------------------------------------------------------------------------
> 
> #!./perl
> 
> BEGIN {
>     chdir 't' if -d 't';
>     @INC = '../lib';
>     require './test.pl';
> }
> 
> use strict;
> 
> plan tests => 2;
> 
> ok( kill(0, $$), 'kill(0, $pid) returns true if $pid exists' );
> ok( !kill(0, 0), 'kill(0, $pid) returns false if $pid does not exist' );

Speaking of kill... have you guys tried running kill(0, undef) with 
certain versions of Perl? The earlier versions (5.8.2) apparently killed 
the parent process instead of erroring out or something.

You just reminded me of that point.

-Garrett

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About