Using SIGINT

前端 未结 6 1936
误落风尘
误落风尘 2020-12-18 15:24

According to this http://www.cplusplus.com/reference/clibrary/csignal/signal.html

SIGINT is generally used/cause by the user. How do i cause a SIG

6条回答
  •  孤城傲影
    2020-12-18 15:55

    void SendSIGINT( HANDLE hProcess )
    {
        DWORD pid = GetProcessId(hProcess);
        FreeConsole();
        if (AttachConsole(pid))
        {
            // Disable Ctrl-C handling for our program
            SetConsoleCtrlHandler(NULL, true);
    
            GenerateConsoleCtrlEvent(CTRL_C_EVENT, 0); // SIGINT
    
            //Re-enable Ctrl-C handling or any subsequently started
            //programs will inherit the disabled state.
            SetConsoleCtrlHandler(NULL, false);
    
            WaitForSingleObject(hProcess, 10000);
        }
    }
    

提交回复
热议问题