Check process existence

Discussion in 'Java' started by nkammah@yahoo.fr, Apr 17, 2006.

  1. Guest

    Hi all,

    I'd like to check if a specific process with a given pid exists. I went
    through the archives of the mailing list and I found a message dated in
    2001, with this piece of code :

    Process p = Runtime.getRuntime().exec("/bin/kill -0 " + pid);
    p.waitFor();
    boolean alive = p.exitValue() == 0;

    I tried it, but I get an IOException :

    java.io.IOException: CreateProcess: \bin\kill -0 3828 error=3
    at java.lang.ProcessImpl.create(Native Method)
    at java.lang.ProcessImpl.<init>(Unknown Source)
    at java.lang.ProcessImpl.start(Unknown Source)
    at java.lang.ProcessBuilder.start(Unknown Source)
    at java.lang.Runtime.exec(Unknown Source)
    at java.lang.Runtime.exec(Unknown Source)
    at java.lang.Runtime.exec(Unknown Source)
    at ProcessExistence.Check.check(Check.java:10)
    at ProcessExistence.Check.main(Check.java:37)

    I am using windows XP.

    Any idea?

    Thank you !

    N.
    , Apr 17, 2006
    #1
    1. Advertising

  2. Guest

    well, probably not ! I am definitly not familiar with unix commands. I
    just copied and past the code. I guess kill doesn't exist on Xp so it
    perfectly makes sense now !

    Would you have any advice? any function I could look at?
    , Apr 17, 2006
    #2
    1. Advertising

  3. On 16 Apr 2006 20:12:27 -0700, wrote:
    > java.io.IOException: CreateProcess: \bin\kill -0 3828 error=3

    [...]
    > I am using windows XP.


    Kill is a unix command. Does it exist on your XP machine?

    /gordon

    --
    [ do not email me copies of your followups ]
    g o r d o n + n e w s @ b a l d e r 1 3 . s e
    Gordon Beaton, Apr 17, 2006
    #3
  4. On 17 Apr 2006 00:38:44 -0700, wrote:
    > I guess kill doesn't exist on Xp so it perfectly makes sense now !


    Well in the post you found from 2001 (written by me I think) it *did*
    say "on unix you can..."

    > Would you have any advice? any function I could look at?


    Someone who knows Windows or XP will have to answer that. Or ask again
    in a Windows newsgroup.

    If there isn't a utility that you can use with Runtime.exec(), there
    may be a native API for accessing the task manager that you can use
    from JNI.

    /gordon

    --
    [ do not email me copies of your followups ]
    g o r d o n + n e w s @ b a l d e r 1 3 . s e
    Gordon Beaton, Apr 17, 2006
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Leon
    Replies:
    1
    Views:
    428
    John Timney \(Microsoft MVP\)
    Oct 18, 2003
  2. TaeHo Yoo
    Replies:
    3
    Views:
    5,951
    John Timney \(Microsoft MVP\)
    Oct 20, 2003
  3. CK
    Replies:
    5
    Views:
    24,073
    Lars-Inge T√łnnessen \(VJ# MVP\)
    Mar 21, 2006
  4. Thomas Scheffler

    XSLT: check existence of a variable

    Thomas Scheffler, Sep 17, 2003, in forum: XML
    Replies:
    0
    Views:
    690
    Thomas Scheffler
    Sep 17, 2003
  5. Tassilo J. Klein

    Check for existence of a tag

    Tassilo J. Klein, Aug 20, 2004, in forum: XML
    Replies:
    9
    Views:
    3,604
    Patrick TJ McPhee
    Aug 23, 2004
Loading...

Share This Page