Code Emulator Help?

I'm trying to create a program that runs other programs for me, and closes them if they begin to fail, run into an infinite loop, or meet an error, without ending the initial program. Not knowing if there's some code that acts like this, I'll just flat out ask if anyone has any leads toward my goals.

If you need a visual idea of what I'm trying to do, think about this:

1
2
3
4
5
6
7
8
9
10
int main()
{
Run_Code(When_Closes Timer)
{
int a = 1;
while (true)
a ++;
}
cout<<"This line of code will run, even if the block above fails.";
}
What you're asking for is impossible, because you can't actually check if a program is stuck in an infinite loop or just doing some very lengthy calculations (not in the general case anyways). I guess you could open a new process (NOT a thread), let it run the program and set a timeout on the process, but that's messy to say the least.
Alright, thanks hanst99. I guess I'll just put it in my impossible folder until I get an epiphany. Thanks for informing me on the subject.
Topic archived. No new replies allowed.