问题
Is it real that the TerminateProcess function in Windows could hang because the threads inside the process were stuck in a deadlock?
Example: Process A is running under Process B's control, now Process A gets into a deadlock and Process B detects this and decides to 'Kill' process A using TerminateProcess.
Would it be successful in killing the hung Process A?
回答1:
Yes, all kernel objects held by the process will be released, including locks.
The main problem with TerminateProcess is that the process has no say in the matter: if it's holding on to any global state (files, shared memory, etc) then you have no guarantee those things are in a consistent state after the process is terminated.
回答2:
Yes. So long as you have the right permissions, TerminateProcess
will kill the other process dead, regardless of how well hung it is.
回答3:
TerminateProcess
will kill each thread (as if TerminateThread
had been used on each and every thread in the process).
But it won't kill threads that are stuck in the kernel (e.g. due to device driver bug).
来源:https://stackoverflow.com/questions/2908603/terminateprocess-and-deadlocks