Hi,
I am trying to create a routine that launches an application from within my
code. However, in certain conditions (unfortunately not all of them avoidable),
the external application goes non-responsive and I'm having problems in
terminating it.
I appologise for any over-simplified or incorrect terminology, but I'm not
a programmer, I'm an engineer, more comfortable with equations and numbers than
codes, and I'm learning Fortran on the go, only as the necessity appears :)
I'll explain a bit what I'm trying to do.
The external application (XFOIL.exe) is launched in batch mode. I've set the
path to the batch file in a CHARACTER variable:
CHAR = 'C:\WingOptim\xfoilrun.bat'
Next, I create the new process for the XFOIL executable:
STARTUPINFO = T_STARTUPINFO(SIZEOF(STARTUPINFO), &
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)
RET = CREATEPROCESS (CHAR, &
'"'//CHAR//'" -CHILD'C, &
NULL_SECURITY_ATTRIBUTES, &
NULL_SECURITY_ATTRIBUTES, &
FALSE, &
0, &
NULL, &
NULL_CHARACTER, &
STARTUPINFO, &
PROCESSINFO)
Finally, after a time that should be more than enough for normal execution,
I close the process and the associated handles.
RET = WAITFORSINGLEOBJECT (PROCESSINFO%HPROCESS, &
20000)
RET = CLOSEHANDLE (PROCESSINFO%HTHREAD)
RET = CLOSEHANDLE (PROCESSINFO%HPROCESS)
RET = TERMINATEPROCESS (PROCESSINFO%HPROCESS, &
JM_EXIT_CODE)
However, there are certain situations when the XFOIL application goes non-
responsive, as I've already mentioned.
The problem that I have is that when this happens, even though control is
transfered back to my main code and its execution continues, a certain
"residual" image of the XFOIL.EXE process remains open in my Windows task list.
If the non-responsive scenario happens several times, each time a new residual
process is created, and slowly my CPU load increases to the point where the
execution of my code becomes impossible (each XFOIL.exe residual eating 25%
of CPU maximum load).
I've also tried to forcefully close XFOIL.exe by passing the taskkill command
to the system. While my XFOIL process is open, i get its ID:
PID = PROCESSINFO%DWPROCESSID
Then, I pass the command to the system:
WRITE (STRING,110) PID
110 FORMAT ('TASKKILL /F /PID ', I5)
RESULT = SYSTEM(STRING)
However, this has no extra effect, and residuals keep building up.
The only way I found to close the residual processes is to manually force them
to close from the task list of the Windows Task Manager. However, this is not
feasible because the execution time of my code is long (a couple of days).
Can anyone point me in the right direction?
Thanks,
Oliviu