Check process existence

N

nkammah

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.
 
N

nkammah

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?
 
G

Gordon Beaton

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
 
G

Gordon Beaton

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top