The whole issue came up when I realized, much to my dismay, that Ruby did not support kill on Win32. Because I need it for a project I'm working on, I decided to write my own. For that I started by scouring the various Win32 programming newsgroups and looking at the Perl source.
I quickly realized that all Perl does is call TerminateProcess(), which is analogous to a "kill -9" in Unix. It'll work, but it's not nice. I downloaded bleadperl and noticed that someone did add this bit of code:
if (PostThreadMessage(IsWin95() ? pid : -pid,WM_USER,sig,0)) {
/* It might be us... */
PERL_ASYNC_CHECK();
return 0;
}
The problem with this code is that it uses the PID as a thread ID. AFAICT this code will never work, not only based on what I've read (I don't think a process' PID has anything to do with a thread ID), but some pure-C experimentation. At least, it never works for me. I tried a few variations to make sure.
So, at some point this week I'm going to submit my own approach to using kill on Win32 systems. And by "my own", I mean one I shamelessly plagiarized off the web, but which seems to work pretty well based on both experimentation and what I've read off of msdn.com.
fork emulation (Score:1)
And kill() only implementing "kill -9 ..." semantics on Win32 is documented in perlport.pod. You'll find that it is not really possible to raise() other signals in arbitrary processes on Windows.
Re:fork emulation (Score:2)
I still have what I believe is a slightly better approach, which is to use CreateRemoteThread + ExitProcess. It's still not as nice as PostThreadMessage, but it's nicer than TerminateProcess. The only drawback is that it won't work on Win9x machines. IMHO the Win9x platform is dead and we shouldn't worry about such things.