TerminateProcess and deadlocks

杀马特。学长 韩版系。学妹 提交于 2019-12-14 03:57:21

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!