jdl
jdl

Reputation: 6333

c++: TerminateProcess (procHandle, 0)

I am using "TerminateProcess (procHandle, 0)" to kill threads. It works for most, but some threads it can't kill. 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

Upvotes: 0

Views: 391

Answers (3)

zangw
zangw

Reputation: 48566

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

Upvotes: 0

Al Kepp
Al Kepp

Reputation: 5980

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."

Upvotes: 1

Roman Ryltsov
Roman Ryltsov

Reputation: 69734

[...] 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.

Upvotes: 1

Related Questions