Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8268559
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T05:55:56+00:00 2026-06-08T05:55:56+00:00

I have many istances of a process running Runtime rt = Runtime.getRuntime(); int i=0;

  • 0

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…

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T05:55:58+00:00Added an answer on June 8, 2026 at 5:55 am

    The Runtime.exec(...) command returns a Process object. You can put your Process objects into a collection and then use the Process.exitValue() method to see if each of the processes has finished. exitValue() throws a IllegalThreadStateException if the process is still running.

    So your code could be something like:

    List<Process> processes = new ArrayList<Process>();
    // noticed I turned your while loop into a for loop
    for (i = 0; i < 10 i++) {
        int arg1 = i + 1;
        Process p = rt.exec("abc.exe "+ arg1);
        processes.add(p);
    }
    ...
    // watch them to see if any of them has finished
    // this can be done periodically in a thread
    for (Process process : processes) {
       try {
           if (process.exitValue() != 0) {
               // it did not exit with a 0 so restart it
               ...
           }
       } catch (IllegalThreadStateException e) {
           // still running so we can ignore the exception
       }
    }
    

    Can I trace this thing on Linux as well as on windows?

    The above code should work on Lunux and Windows if I understand the question.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

First of all I have many Django instances setup and running like this. In
I have similar instances of the same web application running across many domains. I
I have many many files in a folder, and I want to process them
Let's say I have one thread running (I'm creating many instances of this thread),
While analyzing a heap dump using jhat I have observed many instances of DelegatingClassLoader
I have a class that I can have many instances of. Inside it creates
I have only one class with many instances. Every instance is observer of couple
I have a large codebase which has many, many instances of the try {
We have an ASP.NET web application hosted by a web farm of many instances
I have a Class, it will be implemented to be many instances. I want

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.