
Securing Against Infinite Loop - ili
how do online IDEs check for infinite loops and prevent the program from running forever?
======
compressedgas
They don't. The program runs in your browser. It isn't their problem if it
contains an infinite loop. If the page stops responding, you simply reload the
page.

Programming contests use a check program that has a time limit on program
execution.

~~~
ili
But if you check Ideone.com and write a code like this:

while(true){}

the page loads but the ide says time limit exceeded after 5 seconds and stops
the execution. Now, how do you do that?

~~~
brudgers
The _user program_ containing the while-loop could be executed with a _system
call_ as:

    
    
      executeUserProgram(userProgram, timeout=5)...
    

alternatively, the server on which the user program runs could monitor user
processes and terminate any process using excessive CPU time.

Both approaches look for the _effects_ of an infinite loop instead of the
program logic of an infinite loop. Which makes sense since logical analysis
for infinite loops is the Halting Problem and NP-Hard.

~~~
ili
yes that is what i want. is executeUserProgram() a system call? how do i
implement this in windows. I am thinking of forking a process and then kill
the other process after certain amount of time. will it work?

~~~
brudgers

      executeUserProgram() 
    

Is an abstraction. I made up the name to explain how the behavior might be
implemented in the abstract. Implementing the abstraction in a way appropriate
for an actual program is software engineering based on the actual program's
actual constraints.

