Java 中的进程如何判断已经终止?
发布网友
发布时间:2022-06-06 16:03
我来回答
共1个回答
热心网友
时间:2023-10-10 15:56
Process类提供的函数很少,找了一下,能跟判断终止有关的函数只有一个:
exitValue()
public abstract int exitValue()Returns the exit value for the subprocess.
Returns:
the exit value of the subprocess represented by this Process object. by convention, the value 0 indicates normal termination.
Throws:
IllegalThreadStateException - if the subprocess represented by this Process object has not yet terminated.
通过这个函数可得到Process的终止方式。如果未终止,抛出异常。
捕获这个异常就行了。