如何在受监视的过程中检测无限循环

如何在受监视的过程中检测无限循环

本文介绍了如何在受监视的过程中检测无限循环的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Python(winappdbg)监视进程(主要功能是捕获异常).

I'm using Python (winappdbg) to monitor a process (the main feature is to catch the exceptions).

但是我也想检测无限循环.

But I would like also to detect infinite loops.

您知道使用Python做到这一点的方法吗?有无winappdbg ...

Do you know a way to do that with Python?With or without winappdbg ...

推荐答案

检测无限循环的唯一方法是在循环本身中包含对那些条件的测试,这些条件将使它永无止境.

The only way to detect an infinite loop is to include in the loop itself a test for those conditions that would bring it to never end.

例如:如果您的循环应该使变量减小直到它达到零(将是退出条件),则应包括一个测试,以测试我所说的正确的工作条件" .在此示例中,该名称为:var < var_of_previous_iteration.

For example: if your loop is supposed to make a variable decrease until it reaches zero (var == 0 would be the exit condition), you should include a test for what I would call "proper working condition". In this example this would be: var < var_of_previous_iteration.

捕获无限循环的另一种(确定性较低的)方法可能是包括计时器,如果循环持续的时间超过给定的时间限制,则触发异常[这是一个卑鄙的行为,因为执行速度可能会受到例如系统忙于执行其他操作的影响].

Another (less deterministic) way to catch infinite loops could be to include a timer and trigger an exception if the loop last longer than a given time limit [this is a hugly hack though, as execution speed could be affected for example by the system being busy doing something else].

HTH!

这篇关于如何在受监视的过程中检测无限循环的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-23 05:53