Process. In Java exitValue()

Here is the program I use to simply open and close Internet Explorer from my command line program I run my program with Java 6 on the Windows XP operating system:

Runtime runtime = Runtime.getRuntime();       
Process p1 = runtime.exec("C:\\Program Files\\Internet Explorer\\iexplore.exe");
Thread.sleep(5000);
p1.destroy();
Thread.sleep(2000);
System.out.println("p1.exitValue(): "+p1.exitValue())

The exit value is: 1

Javadoc says: by convention, a value of 0 indicates normal termination http://download.oracle.com/javase/6/docs/api/java/lang/Process.html#exitValue ()

Then I commented on P1 Instead of closing the browser from my java program, I closed the window manually (File > Exit) In this case, P1 Exitvalue starts returning '0'

My question is:

>Why does the program return the exit code to "1" in the first case? Whether the JVM will P1 Destroy() is regarded as an abnormal way to terminate the program? > In general, is the exit status code value JVM specific or operating system specific? I see some problems. People have reported the exit code value as "10", "34545", etc

Thank you for reading,

Solution

In fact, these are two questions: -)

>It is almost certain that IE itself captured the fact that it was closed externally and decided to return the error code (see 2 below) So no, the JVM won't put P1 Destroy() is considered a special case, but the affected process may. > The exit value is process specific, not JVM specific (or even operating system specific) In other words, the process itself returns a value to use as an exit value This makes sense when you think of ways to destroy processes that do not involve the JVM

I should mention that in some cases, the process does not affect the exit code Under some UNIX like operating systems, if a process exits due to some serious failure (such as segmentation violation or violent external shutdown), the operating system can set the exit code to a value indicating this value From memory, it is 128 plus the signal number

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>