を使用して子プロセスを強制終了するのに問題がありますTerminateProcess
。この関数を呼び出しますが、プロセスはまだそこにあります (タスク マネージャー内)。このコードは同じprogram.exeを何度も起動して何度も呼び出され、これらのプロセスはタスクマネージャーにあり、良くないと思います。実際には、program.exe と conhost.exe という 2 つのプロセスが常に作成されます。
どんな助けでも本当に感謝します。
コードは次のとおりです。
STARTUPINFO childProcStartupInfo;
memset( &childProcStartupInfo, 0, sizeof(childProcStartupInfo));
childProcStartupInfo.cb = sizeof(childProcStartupInfo);
childProcStartupInfo.hStdInput = hFromParent; // stdin
childProcStartupInfo.hStdOutput = hToParent; // stdout
childProcStartupInfo.hStdError = hToParentDup; // stderr
childProcStartupInfo.dwFlags = STARTF_USESTDHANDLES | STARTF_USESHOWWINDOW;
childProcStartupInfo.wShowWindow = SW_HIDE;
PROCESS_INFORMATION childProcInfo; /* for CreateProcess call */
bOk = CreateProcess(
NULL, // filename
pCmdLine, // full command line for child
NULL, // process security descriptor */
NULL, // thread security descriptor */
TRUE, // inherit handles? Also use if STARTF_USESTDHANDLES */
0, // creation flags */
NULL, // inherited environment address */
NULL, // startup dir; NULL = start in current */
&childProcStartupInfo, // pointer to startup info (input) */
&childProcInfo); // pointer to process info (output) */
CloseHandle( hFromParent );
CloseHandle( hToParent );
CloseHandle( hToParentDup );
CloseHandle( childProcInfo.hThread);
CloseHandle( childProcInfo.hProcess);
TerminateProcess( childProcInfo.hProcess ,0); //this is not working, the process