How can I kill a system process which is frozen
조회 수: 8 (최근 30일)
이전 댓글 표시
I'm working on some genetic algorithm optimisation code which interfaces with Xfoil for the analysis, using a system() command to run Xfoil. Sometimes Xfoil freezes (maybe due to a "bad" aerofoil shape), and this halts the entire optimisation process. I've added a simple timer based "kill exe" callback function, which is designed to kill the Xfoil exe run after a certain amount of time - this should give any "good" run a chance to finish, and should close any "bad" run. However, the callback function is not able to be called while Xfoil is running. It appears that even though the timer delay has ended and the TimerFcn() is triggered, Matlab cannot process the "kill exe" callback function while a system process is running.
So basically I can't kill the frozen system process. Anyone have any way around this?
댓글 수: 0
채택된 답변
Mohammad Sami
2020년 8월 29일
편집: per isakson
2021년 4월 2일
You can use .Net System.Diagnostic.Process to run it. This way you will also be able to terminate the program.
process = System.Diagnostics.Process();
process.StartInfo.FileName = 'java.exe';
process.StartInfo.Arguments = 'some args';
process.StartInfo.UseShellExecute = false;
process.StartInfo.RedirectStandardInput = false;
process.StartInfo.CreateNoWindow = false;
process.Start();
processisrunning = ~process.HasExited;
You can use the following command to kill the exe.
process.Kill();
댓글 수: 2
Walter Roberson
2020년 8월 30일
https://docs.microsoft.com/en-us/dotnet/api/system.diagnostics.processstartinfo.redirectstandardoutput?view=netcore-3.1
https://stackoverflow.com/questions/16256587/redirecting-output-to-the-text-file-c-sharp
In order to redirect from a file you need to set up the process to use the command shell and then you use the typical command line.
More recommended is to not use a shell and to say that you want to redirect standard input and standard output, and then access the streams and write the appropriate content to the stream or read it from the stream. You can get buffer-fulls of content as they are generated -- including being able to set up callbacks when the stream is ready for more input or when more output is available. You can then also tie in a timer callback to know when the process has gone silent.
추가 답변 (0개)
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!