in reply to catching infinite loops

I have never put in any gimmicks to catch an (unintended) infinite loop, though I have put them in place to catch when an infinite loop has stopped.

As has already been pointed out, the customary method is to ask the OS to send you an alarm signal and wake you up. But... are you absolutely certain that you need to do this? I sense a possible design problem here, though I have no idea what your project entails.

Replies are listed 'Best First'.
Re: Re: catching infinite loops
by cLive ;-) (Prior) on Apr 20, 2001 at 23:38 UTC
    replace $x with $y, both of which are externally input to script from config file. When you have tested it works, infinite loop can't happen. But, if an external developer decides to add their own config file, if they make a typo, the replace loop could go on forever.

    eg, ee -> e is OK, but would need to be looped until it fails. eeeee -> eee -> ee -> e -> done.

    But, say they entered these the other way round by mistake. eee -> eeeeee -> eeeeeeeeeeee ....

    Not the exact case, but that should give you an idea...

    cLive ;-)

      In that case a time-based catch is going to be rather inadequate. A fast memory leak doesn't take long to hurt.

      Instead I would suggest either setting a maximum number of iterations, or looking into what your OS supplies in the way of things like ulimit...