Can I send a ctrl-C (SIGINT) to an application on Windows?

前端 未结 17 2798
甜味超标
甜味超标 2020-11-22 09:15

I have (in the past) written cross-platform (Windows/Unix) applications which, when started from the command line, handled a user-typed Ctrl-C combinat

17条回答
  •  梦谈多话
    2020-11-22 09:59

    Somehow GenerateConsoleCtrlEvent() return error if you call it for another process, but you can attach to another console application and send event to all child processes.

    void SendControlC(int pid)
    {
        AttachConsole(pid); // attach to process console
        SetConsoleCtrlHandler(NULL, TRUE); // disable Control+C handling for our app
        GenerateConsoleCtrlEvent(CTRL_C_EVENT, 0); // generate Control+C event
    }
    

提交回复
热议问题