title: How to identify and terminate a javascript in infinite loop programmatically?
body: <p>It is more of a hypothetical question. There is sometimes a possibility of a javascript code entering an infinite loop and blocking everything specially in early stages of development. I know the best solution would be to code so that such a situation never arises but what if in a certain case it is impossible to write a fullproof code (maybe because we don't have control on the input or something else).</p>
  
  <p>Is there any way we can programmatically determine when a code is in an infinite loop and terminate it?</p>
  
  <p>Maybe running the pieces of code where such a thing could happen in a separate thread or in a child process synchronously and determining when that thread/process is in an infinite loop.</p>
  
  <p>How could one go about doing that? Is it possible to determine when a thread (either main or child) is in an infinite loop by determining the CPU usage by that thread alone?</p>
  
  <p>Based on the discussion had in comments below I realise that identifying a blocking infinite loop would be impossible on the basis of tracking repetitive execution of similar statements  and high resource utilization alone. So I think that the solution lies in a combination of both. But that brings as back to our earlier problem. How can we gauge the CPU usage by a script?</p>