Can I send SIGINT to a Python subprocess on Windows?
Asked Answered
C

1

5

I've got a Python script managing a gdb process on Windows, and I need to be able to send a SIGINT to the spawned process in order to halt the target process (managed by gdb)

It appears that there is only SIGTERM available in Win32, but clearly if I run gdb from the console and Ctrl+C, it thinks it's receiving a SIGINT. Is there a way I can fake this such that the functionality is available on all platforms?

(I am using the subprocess module, and python 2.5/2.6)

Castellano answered 8/7, 2009 at 0:34 Comment(0)
Y
1

Windows doesn't have the unix signals IPC mechanism.

I would look at sending a CTRL-C to the gdb process.

Yuhas answered 8/7, 2009 at 0:52 Comment(8)
According to the link below, you can't send CTRL+C ??Castellano
I would send the fake key sequence to the GDB process. Sort of like a Macro program. It is definitely not pretty. Another option is to instrument the gdb process with a reliable win32 IPC mechanism.Yuhas
Fake key sequence doesn't work. It's not GDB that processes the key sequence into an interrupt. The shell catches the CTRL+C, and then turns it into some sort of IPC event that's picked up by gdb and interpreted as a SIGINT (even though windows as we know it doesn't have SIGINT) When you say "instrument the gdb process with a reliable win32 IPC mchanism" you mean actually much around in the GDB code right? Like actually go and drop in a named pipe or some flag or something that I could set externally? Let's assume that is also not an option in this case.Castellano
Ok, let me try to figure this out. It is interesting. So you have a python process that starts a GDB process that starts its own target process. You want to have the python process cause a break or interuption to occur in the windows process. I need to know a little more. Is the target process any windows process or ones that were compiled with Cygwin. Which GDB is this (Cygwin, a custom one, etc)? This will help me help you zone in on the answer. Cheers.Yuhas
What I'm writing is a frontend for GDB, so it could potentially be any of the above. The GDB I'm working with now (the one that's giving me fits) is codesourcery g++, ( codesourcery.com ) Which appears to be built using the MinGW system. The idea is to allow people to use any GDB they like, so a cygwin binary, or a mingW thing or whatever are all on the table. I've also tested a simple case by using MinGW gcc to build a simple executable that just prints a counter until it "recieves SIGINT" at which time it prints a message indicating so. I get the same behavior with it.Castellano
Ok, that is very helpful. Is there any console associated with these processes? Are all the processes in a process group?Yuhas
I haven't been able to get anything to work, either allowing the subprocess to inherit the parent's console, or using the creationflags argument to do a whole variety of things, including creating a new console, creating the process as a "detached" process, and starting it in a new process group. (Some of these methods are explained in the link below, while still being almost completely unhelpful)Castellano
Creation flags docs here: msdn.microsoft.com/en-us/library/ms684863(VS.85).aspxCastellano

© 2022 - 2024 — McMap. All rights reserved.