我不能杀死一个子进程使用TerminateProcess [英] I am not able to kill a child process using TerminateProcess

查看:270
本文介绍了我不能杀死一个子进程使用TerminateProcess的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个问题,使用 TerminateProcess 杀死子进程。我调用这个函数和进程仍然在那里(在任务管理器)。这段代码被称为很多次启动相同的program.exe多次,这些过程中有任务管理器,我认为不好。
实际上一直创建两个进程:program.exe和conhost.exe。

I have a problem to kill a child process using 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. Actually is created two process all the time: the program.exe and conhost.exe.

我真的很感激任何帮助。

I will really appreciate any help.

这里是代码:

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:


  • 你不能杀死在不同安全上下文中运行的进程,调用TerminateProcess(参见此处

  • 该过程为< a href =http://blogs.technet.com/b/markrussinovich/archive/2005/08/17/unkillable-processes.aspx =nofollow>在内核中执行某些操作模式(例如某些未完成的驱动程序I / O操作等) - 我相信这是由Vista引入的,但我可能是错误的

  • you can't kill a process running under a different security context than the one of the process which calls TerminateProcess (see here)
  • the process is doing something in kernel mode (e.g. some unfinished I/O operations by driver, etc) - I believe this was introduced with Vista, but I might be wrong

这篇关于我不能杀死一个子进程使用TerminateProcess的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆