Killing .exe program started from Matlab

조회 수: 7 (최근 30일)
Francesco
Francesco 2012년 7월 19일
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
Francesco
Francesco 2012년 7월 19일
By the way.
The solution reported here: http://www.mathworks.ch/matlabcentral/answers/43823-running-external-program-from-matlab-for-a-given-amount-of-time is not working since I have several instances of the .exe program running and I want to kill just one of them.
Concerning the more general purpose answer, I fear it might be a bit too generic for my understanding...
Francesco
Francesco 2012년 7월 19일
Thanks Jan Simon.
I am using Matlab 2012a on a Mindows 7 64bit. I am using a local matlabpoool, so the .exe runs on the same computer running matlab. By the way, the .exe is located in the work folder.
Unfortunately I was not able to avoid the .exe getting stuck (it is happening to others as well). I know it is not nice but at the end I had to accept it..

댓글을 달려면 로그인하십시오.

답변 (2개)

Jan
Jan 2012년 7월 19일
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
Francesco
Francesco 2012년 7월 20일
편집: Francesco 2012년 7월 20일
Thank you Jan Simon
As you said, the tricky part is to get the PID. A colleague already suggested running tasklist before and after system in order to see the PID of the created task. However, due to the parallel nature it is quite probably that I will have several jobs starting at the same time and the trick would probably not work.
I had a look at the FEX submissions you suggested. If I am not wrong, the first one does not give back the PID. The second is unfortunately for Linux only...
Jan
Jan 2012년 7월 20일
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.

댓글을 달려면 로그인하십시오.


Francesco
Francesco 2012년 7월 23일
I finally decided to save time and go for a dirty solution.
I replicated the .exe file (one per lab). Now every lab calls program_labID, so that I can always kill the program_labID task being sure that it will only affect the lab I want.
I know it's super ugly, but unfortunately I was unable to get anything cleaner. Thank you anyhow for the help!
  댓글 수: 1
Jan
Jan 2012년 7월 23일
No, this is not super ugly. You could create hard-links to avoid data duplication.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Programming에 대해 자세히 알아보기

제품

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by