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

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

Thread Previous | Thread Next
Steve Hay
April 19, 2007 03:15
Re: [PATCH] Fix kill(0, $pid) on Windows
Message ID:
Jan Dubois wrote:
> On Wed, 18 Apr 2007, Steve Hay wrote:
>> Jan Dubois wrote:
>>> Therefore `kill(15, undef)` should send signal 15 to all processes
>>> in the current process group, including the process issuing the
>>> kill() call itself.
>> Is kill(15, $pid) supposed to work on Windows? I find that it has no
>> effect (at least when $pid is another perl.exe process).
> It works for me (see sample at the end of the message):
> D:\tmp>perl
> cmd=d:\perl820\bin\perl.exe -x
> 5032 pid=4600
> 4332 starting
> 5032 kill=1
> Terminating on signal SIGBREAK(21)
> 5032 done
> You'll notice that SIGTERM(15) is mapped to SIGBREAK(21) on Windows.

I get the same result as you using your test program, but I still have 
two problems or misunderstandings.

Firstly, what I was trying (and which still doesn't work) is to start a 
perl.exe in one command prompt and note its PID, e.g.

 >perl -le "print $$; sleep 60"

and then try to kill it using a perl.exe in another command prompt:

perl -e "kill 15, 2508"

I expected that to kill the first perl.exe (PID 2508), but it doesn't. 
Trying to kill the cmd.exe parent of PID 2508 instead (like your program 
does) also doesn't work.

Of course, your program is different in that the perl.exe (and its 
parent cmd.exe) being killed is a child of the perl.exe that is trying 
to kill it, whereas I'm playing with two separate process trees. Is this 
expected behaviour?

Secondly, if I change the "kill 15, $pid" in your program to "kill 15, 
undef" instead then I was expecting the whole process tree to be killed, 
including the perl.exe that is issuing the kill(), as per your comment 
quoted at the very top of this email.

However, I still find that only the cmd.exe and its child perl.exe get 
killed, and the top-level perl.exe that issued the kill() hangs around 
for another 5 seconds until it says "done" and exits. This doesn't seem 
to be what you suggested would happen, unless I've misunderstood you.


Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About