2

を使用して子プロセスを強制終了するのに問題があります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 
4

1 に答える 1

5

私が知っている2つの考えられる理由があります。

  • TerminateProcess を呼び出すプロセスとは異なるセキュリティ コンテキストで実行されているプロセスを強制終了することはできません (こちらを参照) 。
  • プロセスがカーネル モードで何かを実行している(たとえば、ドライバーによる未完了の I/O 操作など) - これは Vista で導入されたと思いますが、間違っている可能性があります
于 2012-09-18T21:35:34.350 に答える