Stories
Slash Boxes
Comments
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

djberg96 (2603)

djberg96
  (email not shown publicly)

Journal of djberg96 (2603)

Sunday May 11, 2003
12:01 AM

subscribe perl5-porters

[ #12116 ]
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.

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
 Full
 Abbreviated
 Hidden
More | Login | Reply
Loading... please wait.
  • 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.

    • 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.