开发者

c++: TerminateProcess (procHandle, 0)

I am using "TerminateProcess (procHandle, 0)" to kill threads. It works for most, but some threads it can't kil开发者_开发知识库l. WHY? Also the task manager can't kill those threads either.

Is there a way to force kill any thread? What else can I do?

thx


Normally you cannot kill processes of other users if you don't have required rights. For example it is not possible to kill processes running as SYSTEM user, processes of other users on a terminal server, etc.

Citation from MSDN: "The handle must have the PROCESS_TERMINATE access right. For more information, see Process Security and Access Rights."


[...] These scenarios are usually the result of buggy device drivers that don’t properly handle the cancellation of outstanding I/O requests.

See Unkillable Processes.


I have met the same cases as you mentioned.

Since the TerminateProcess is asynchronous and The terminated process cannot exit until all pending I/O has been completed or canceled. When a process terminates, its kernel object is not destroyed until all processes that have open handles to the process have released those handles. Citation from MSDN.

Also the I/O pending the normal case, there are two ways to cancel IO.

  1. call CancelIo to cancel IO manually.
  2. reduce write timeout value from registry HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\Disk\TimeOutValue
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜