如何检查进程是否没有响应? [英] How to check if process is not responding?

查看:70
本文介绍了如何检查进程是否没有响应?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果另一个进程没有响应,是否有可能从代码中检查?

Is there any possibility to check from code if another process is not responding?

问题是即使应用程序崩溃并且在管理器的列表中标记为未响应",Process.Responding 属性仍然返回true".

The problem is even if the app is crashed and on the Manager's list is marked as 'Not Responding', the Process.Responding property is still returning 'true'.

'Exited' 事件和函数 'WaitForExit' 将执行任何操作,如果进程是 - 什么是明确的 - 退出.所以这不是重点.

The 'Exited' event and function 'WaitForExit' are do any action if the process is- what is clear- exited. So it's not the point.

两个字的问题;我需要知道应用程序崩溃了.如何从代码中查看?

Problem in two words; I need to know that the application is crashed. How to check it from the code?

感谢您的宝贵时间.

推荐答案

这个问题没有通用的解决方案.

无法判断特定进程是否挂起,因为术语挂起"完全取决于正在执行的进程的上下文.

It is impossible to tell if a particular process is hanging or not, because the term "hanging" is entirely dependent upon the context of the process that is executing.

挂起过程将始终执行其编码要做的事情.开发人员可能编码不当,但 Windows 无法对正确/错误做出假设.

The hanging process will always do what it was coded to do. The developer may have coded it badly, but Windows can't make assumptions about what is right/wrong.

可以尝试的想法可能是:

Possible ideas to try might be:

  1. Process.Responding 调用将指示正在执行 Windows 消息循环的进程是否正在响应.

  1. The Process.Responding call will indicate whether or not a process that is executing a windows message loop is responding.

对于更一般的情况,一种可能的解决方案可能是每隔一段时间轮询进程的内存使用情况,如果在足够长的时间后它没有改变,则假设它已挂起.您可以使用 Process.WorkingSet64 来做到这一点.但是,我预计这会导致一些误报 - 不处理任何内容的稳定进程可能会挂起.它还会导致出现漏报,出现内存泄漏的挂起进程看起来正在做一些有用的事情,而实际上它被卡在一个循环中.

One possible solution for the more general case might be to poll the memory usage for the process at intervals and if it doesn't change after enough time, assume that it is hung. You could do this with Process.WorkingSet64. However, I expect that this would cause a number of false positives - stable processes that are not processing anything might appear to be hanging. It would also cause false negatives where a hanging process that had a memory leak would appear to be doing something useful, when in fact it was stuck in a loop.

如果进程写入 StandardError/StandardOutput 流(就像许多控制台应用程序那样),那么您可以尝试监听这样的输出:Process.BeginOutputReadLineProcess.BeginErrorReadLine.如果在给定的时间内没有这样的输出,你可以推断它已经挂了.

If the process writes to the StandardError/StandardOutput streams (as many console applications do), then you could try listening for such output: Process.BeginOutputReadLine and Process.BeginErrorReadLine. If there is no such output within a given period, you might deduce that it has hung.

但是你不会找到任何在一般情况下有效的东西.

But you're not going to find anything that works in the general case.

这篇关于如何检查进程是否没有响应?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆