I have many istances of a process running
Runtime rt = Runtime.getRuntime();
int i=0;
int arg1;
while(i<10){
arg1 = i+1;
Process p = rt.exec("abc.exe "+ arg1);
i++;
}
Each process is being run with different argument value here arg1 is parameter to that process abc.exe, I want to keep a check on all these processes whether they are running or any of them crashed. In case of crash, I want to restart it. How can I keep track of all these process and periodically check if they are crashing or not?
Can I trace this thing on Linux as well as on windows? Read some articles on it but this one is bit different, since it involves multiple occurrences and have to check on some particular process only…
The
Runtime.exec(...)command returns aProcessobject. You can put yourProcessobjects into a collection and then use theProcess.exitValue()method to see if each of the processes has finished.exitValue()throws aIllegalThreadStateExceptionif the process is still running.So your code could be something like:
The above code should work on Lunux and Windows if I understand the question.