简体   繁体   English

TerminateProcess和死锁

[英]TerminateProcess and deadlocks

Is it real that the TerminateProcess function in Windows could hang because the threads inside the process were stuck in a deadlock? Windows中的TerminateProcess函数是否真的可以挂起,因为进程内的线程陷入了死锁中,这是真的吗?

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. 示例:进程A在进程B的控制下运行,现在进程A陷入死锁,进程B检测到该死锁,并决定使用TerminateProcess来“杀死”进程A。

Would it be successful in killing the hung Process A? 杀死挂起的进程A是否成功?

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就会杀死另一个死掉的进程,无论它挂得多么好。

TerminateProcess will kill each thread (as if TerminateThread had been used on each and every thread in the process). TerminateProcess将杀死每个线程(就像已在进程中的每个线程上使用TerminateThread一样)。

But it won't kill threads that are stuck in the kernel (eg due to device driver bug). 但是它不会杀死滞留在内核中的线程(例如由于设备驱动程序错误)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM