Slash Boxes
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)

  (email not shown publicly)

Journal of djberg96 (2603)

Saturday December 04, 2004
09:09 PM

SIGINT on Windows

[ #22147 ]
I've been working on some C code to send a Ctrl-C to a Windows console process. Consider the following code snippet:

$SIG{INT} = sub{ die "Caught signal\n" };

print "PID: $$\n";

   print "Looping\n";

If you run this in a terminal, and hit Ctrl-C, the sig handler will (eventually) pick it up and terminate. But, if you were to run that and then, in a separate program, try to do "kill(2,$pid) or die $!" it won't work. It's going to return "invalid parameter". What's going on?

The problem is in the way the GenerateConsoleCtrlEvent() works. In short, you can't kill a remote console process like that. So, I've been researching the hell out of this trying to figure out how it can be done. I'm pretty sure it CAN be done, but it's been rough going so far.

My research leads me to believe that this can be accomplished with something along the lines of this abbreviated code:

WriteProces sMemory()

But, so far all I've been able to do is kill the process, while causing an Application Error in perl.exe itself. So, I'm doing something wrong but I don't know what. I've posted my problem on one of the windows newsgroups. We'll see what happens.

PS - I have no idea why there's a space showing up in "WriteProcessMemory" above. It's not that way in my text.

update: I have been told that the latter approach still won't work. It *might* be possible with AttachConsole(), but that would XP or later only. We shall see.

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
More | Login | Reply
Loading... please wait.