Results 1 to 5 of 5
  1. #1
    Join Date
    May 2008
    Location
    India,Kolkatta
    Posts
    50
    Rep Power
    0

    Unhappy Process running or not

    Hi all,

    i want a code to know whether a Process is running or not. and if it running do this anf if not do another thing.

    Please help Thanks in advance..
    Thanks & Regards
    Subroto Bhattacharjee:)

  2. #2
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    I don't think there is a direct way to test it. Did you rad the Java doc for Precess members, there may be a hint, but cannot be a direct way. But working on a thread it's possible.

  3. #3
    serjant's Avatar
    serjant is offline Senior Member
    Join Date
    Jun 2008
    Location
    Ukraine,Zaporozhye
    Posts
    487
    Rep Power
    7

    Default

    I explain the way how i did that in Java on linux with the help of shell script command:

    run the command from java application which is:
    Java Code:
    String command="ps -A -U "+System.getProperty("user.name")+" -d";
    try {
          String line;
          Process p = Runtime.getRuntime().exec(command);
          BufferedReader input =new BufferedReader(new InputStreamReader(p.getInputStream()));
          while ((line = input.readLine()) != null) {
            System.out.println(line);
          }
          input.close();
        }catch (Exception err) {
          err.printStackTrace();
        }
    Then read line by line the output and check if the process was launched by you.
    Last edited by serjant; 10-15-2008 at 11:44 AM.

  4. #4
    collin389 is offline Senior Member
    Join Date
    Nov 2009
    Posts
    235
    Rep Power
    5

    Default

    You could run int = Process.exitValue(); and see if it throws an IllegalThreadStateException.

  5. #5
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

Similar Threads

  1. Read Process Memory
    By newms86 in forum New To Java
    Replies: 2
    Last Post: 07-07-2008, 05:14 PM
  2. inter process communication
    By ibtehal in forum Networking
    Replies: 5
    Last Post: 06-23-2008, 01:35 AM
  3. i need help in http process
    By sureshjava in forum New To Java
    Replies: 0
    Last Post: 01-29-2008, 04:56 AM
  4. How can I set a time out on the loading process
    By paul in forum Advanced Java
    Replies: 1
    Last Post: 08-07-2007, 04:54 AM
  5. Linux process from java
    By Ed in forum New To Java
    Replies: 2
    Last Post: 07-04-2007, 05:03 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •