Reputation: 6333
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
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.
CancelIo
to cancel IO manually.HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\Disk\TimeOutValue
Upvotes: 0
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
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