如何检查进程没有响应?进程

2023-09-03 02:03:24 作者:冷香縈遍紅樓夢

是否有可能从code,以检查是否另一个进程没有响应?

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

现在的问题是,即使应用程序是崩溃和经理的名单上被标记为未响应,则Process.Responding属性仍返回真。

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'.

在'退出的事件和功能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.

在两个词的问题;我需要知道该应用程序崩溃。如何从code检查呢?

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.

该挂起的进程将永远做什么是codeD做。开发人员可以有codeD是很糟糕,但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:

的Process.Responding电话会议将指示是否正在执行一个窗口消息循环响应的过程。

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.BeginOutputReadLine Process.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.