subscribe perl5-porters

djberg96 on 2003-05-11T05:01:17

I just subscribed to the Perl5 Porters list. I might actually have some source code to contribute to the next release of Perl!

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

jand on 2003-05-11T06:15:36

The code you are quoting is for killing "processes" created by the fork() emulation. They are not real processes, but just different threads in the same process. The negative thread id is used as a process id here.

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

djberg96 on 2003-05-11T13:05:16

Ah, ok. I didn't realize that it was for the fork emulation.

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.