sureshd
sureshd

Reputation: 565

In Java What is the exit value of a process which is killed in the background through Linux shell using process id

Using Java, I am executing a process in linux environment like below

Process startPingProcess = Runtime.getRuntime()().exec(ping -c 50 74.125.228.71);

we check whether process has completed its execution using startPingProcess.exitValue() in java, it will return 0 if completed normally.

Suppose if I'm killing the above started process in the middle by executing below code

Runtime.getRuntime()().exec(kill -2 processid); - where processid is process id of above started process

What is exitValue of startPingProcess object?

Your help is much appreciated! Thanks

Upvotes: 2

Views: 643

Answers (1)

fge
fge

Reputation: 121720

This is not a Java specific question. The return code will be the same for all Unix systems here (at least I have never seen a Unix system not behaving this way): 128 + the number of the signal which caused the process to terminate. No idea for Windows...

Therefore, 130 in your case. In C, you'd check (after a call to waitpid() for instance) whether a process has been terminated by a signal using WIFSIGNALED(status).

Upvotes: 2

Related Questions