-
Notifications
You must be signed in to change notification settings - Fork 8.4k
termination on ctrl + break #4254
Copy link
Copy link
Closed
Labels
Issue-Questionideally support can be provided via other mechanisms, but sometimes folks do open an issue to get aideally support can be provided via other mechanisms, but sometimes folks do open an issue to get aResolution-FixedThe issue is fixed.The issue is fixed.WG-Interactive-Consolethe console experiencethe console experience
Metadata
Metadata
Assignees
Labels
Issue-Questionideally support can be provided via other mechanisms, but sometimes folks do open an issue to get aideally support can be provided via other mechanisms, but sometimes folks do open an issue to get aResolution-FixedThe issue is fixed.The issue is fixed.WG-Interactive-Consolethe console experiencethe console experience
Type
Fields
Give feedbackNo fields configured for issues without a type.
I'm working on an application that launches powershell scripts (using powershell core) to setup and launch processes. I want to be able to send ctrl+break or ctrl+c signals to these powershell processes and their child processes to cleanly shut them down.
When I create the powershell process I set
CREATE_NEW_PROCESS_GROUPwhich implicitly callsSetConsoleCtrlHandler(NULL,TRUE)which effectively turns off ctrl+c for the created process and its children. So when stopping my launched powershell processes, I callGenerateConsoleCtrlEventand send the powershell's process group a ctrl+break. While this effectively closes child processes of the powershell process, it puts the powershell process into debug mode which is undesirable.I have tried 2 strategies to work around this both fail in different ways:
In the powershell process I launch, I call
SetConsoleCtrlHandler(NULL,FALSE)to turn ctrl+c back on and have my application generate ctrl+c events. This works perfectly the first time. However, oddly, the parent console now no longer seems to propogate ctrl+c to child processes. For example, if I run my app and start some ps processes and succesfully stop them with ctrl+c events and then terminate my app and THEN runping 8.8.8.8 -t, ctrl+c does nothing.I register a new handler to capture BREAK events in the powershell process in hopes this will override the powershell behavior that enters debug mode. However, when this handler is called, even if I have it do absolutely nothing, via a ctrl+break signal, an access violation is thrown in the powershell process.
Is there a clean way to disable the debug behavior invoked from ctrl+break or is there any thoughts why ctrl+c signals do not get propogated if I turn that handler on?