Skip to content

termination on ctrl + break #4254

@mwrock

Description

@mwrock

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_GROUP which implicitly calls SetConsoleCtrlHandler(NULL,TRUE) which effectively turns off ctrl+c for the created process and its children. So when stopping my launched powershell processes, I call GenerateConsoleCtrlEvent and 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:

  1. 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 run ping 8.8.8.8 -t, ctrl+c does nothing.

  2. 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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Issue-Questionideally support can be provided via other mechanisms, but sometimes folks do open an issue to get aResolution-FixedThe issue is fixed.WG-Interactive-Consolethe console experience

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions