TerminateProcess 和死锁
Windows 中的 TerminateProcess 函数真的会因为进程内的线程陷入死锁而挂起吗?
示例:进程 A 在进程 B 的控制下运行,现在进程 A 陷入死锁,进程 B 检测到这一情况并决定使用 TerminateProcess“终止”进程 A。
是否能够成功杀死挂起的进程A?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
是的,进程持有的所有内核对象都将被释放,包括锁。
TerminateProcess 的主要问题是进程在这件事上没有发言权:如果它保留任何全局状态(文件、共享内存等),那么您无法保证这些东西在进程终止后处于一致的状态。
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.
是的。只要您拥有正确的权限,TerminateProcess 就会杀死其他进程,无论它挂起的情况如何。
Yes. So long as you have the right permissions,
TerminateProcess
will kill the other process dead, regardless of how well hung it is.TerminateProcess
将终止每个线程(就好像在进程中的每个线程上使用了TerminateThread
)。但它不会杀死卡在内核中的线程(例如由于设备驱动程序错误)。
TerminateProcess
will kill each thread (as ifTerminateThread
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).