Killing .exe program started from Matlab
Show older comments
I am doing an optimization with ga (with matlabpool parallel computing). From within my function evaluation, I call an external .exe program (XFoil, somebody might know it). At the moment I am simply using "system" for running the .exe program.
system(['xfoil.exe < prof_name.cmd > prof_name.out']);
where prof_name.cmd is an input file for the program and prof_name.out a file that I ask only for avoiding having my screen full of useless messages.
My problem is that sometimes the .exe program gets in a loop and, therefore, the control does not go back to Matlab and my optimization gets stuck. Thus, I would like to kill the .exe after a given time but this is not possible using the system command.
Does anybody have a suggestion?
Thanks
P.S. I considered assembling a job (one per generation) calling several tasks (the evaluation of the individuals) and using the timeout property:
set(j, 'Timeout', 60)
to end the task. Although this would unlock the optimization, it would also leave several instances of the .exe program running (thus quickly reducing the available computational power)
3 Comments
Jan
on 19 Jul 2012
Which OS are you using? Do you start the exe files locally or remotely? Why do they fall into an infinite loop? A straight approach would be to avoid that the exe files are blocked, while killing them externally is more a crude and brute workaround.
Francesco
on 19 Jul 2012
Francesco
on 19 Jul 2012
Answers (2)
Jan
on 19 Jul 2012
0 votes
You can obtain the ProcesID using the OS-command tasklist. Then the task can be kill by taskkill.
The identification of a started task in the tasklist output is not trivial. It would be smarter to start the exe using spawn in a C-mex function, such that you get the ProcessID directly. Perhaps these FEX submissions help: FEX: spawn and FEX: clientserver-framework.
2 Comments
Jan
on 20 Jul 2012
Althout it does not reply the PID directly, you could be able to modify the code such that it does. If the C-stuff is not your business, adjust the code as far as you can and post a new question in this forum.
Categories
Find more on Programming in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!