我在使用TerminateProcess
. 我调用这个函数并且进程仍然存在(在任务管理器中)。这段代码被多次调用,多次启动相同的program.exe,这些进程在任务管理器中,我认为这不好。实际上一直创建两个进程:program.exe和conhost.exe。
我将非常感谢任何帮助。
这是代码:
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