jeudi 24 août 2017

Limit execution time of system() call in C++ [duplicate]

This question already has an answer here:

I have a program which makes use of an external .exe that accepts text files as command inputs. I'm making a call such as this:

system("xfoil.exe < create_results.txt > nul");

That executes the program "xfoil" with the correct parameters that I write in the create_results.txt file.

The problem is sometimes the execution does not converge and enters an infinite loop, so I need a way to stop the execution of the system() call after it exceeds a set time.

If I am not mistaken I should use some kind of threading to do this, the problem is I cannot change the program, so I cant send signals while it's executing to check if it has entered an infinite loop. The only way I can think of is a timeout, but I have not found how to execute a thread for x amount of time and then kill it (in c++) without producing leaks.

I'm doing this in windows, C++11

Aucun commentaire:

Enregistrer un commentaire