[英]I am not able to kill a child process using TerminateProcess
I have a problem to kill a child process using TerminateProcess
. 我在使用
TerminateProcess
杀死子进程时遇到问题。 I call to this function and the process still there (in the Task Manager). 我调用了此函数,进程仍然存在(在任务管理器中)。 This piece of code is called many times launching the same program.exe many times and these process are there in the task manager which i think is not good.
这段代码被多次调用,多次启动同一program.exe,而这些过程在任务管理器中都存在,我认为这不好。 Actually is created two process all the time: the program.exe and conhost.exe.
实际上一直都在创建两个进程:program.exe和conhost.exe。
I will really appreciate any help. 我将非常感谢您的帮助。
Here is the code: 这是代码:
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
There are two possible reasons that I know of: 我知道有两个可能的原因:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.