|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object java.lang.Process PIRL.Utilities.UNIX_Process
public class UNIX_Process
A UNIX_Process is an adapter for the UNIXProcess implementation of the abstract Process class that provides access to hidden information.
The API for the Java Process class, as of Java 1.6, has an unfortunate shortcoming: The user is unable to access the process identification (PID) of the executed process nor provide the timeout argument to the Object.wait method used by the waitFor method. Process is an abstract class that is implemented by a host OS dependent class - UNIXProcess for UNIX systems - which relies on JNI methods that make the necessary host process management system calls.
For the UNIXProcess class (as of Java 1.6) the PID value is held in
the private "pid" variable. UNIX_Process provides an ID()
method to get the PID value.
The ability to provide the timeout argument is a trivial modification
of the waitFor method. UNIX_Process provides a waitFor(long)
method that limits the wait for the process to exit
to a timeout value.
An exited()
method provides direct access to the running/exited
flag for the process.
All Process API methods are simply passed to the underlying Process.
Process
Field Summary | |
---|---|
static String |
ID
Class identification name with source code version and date. |
Constructor Summary | |
---|---|
UNIX_Process(Process process)
Construct a UNIX_Process for a Process object on a UNIX system. |
Method Summary | |
---|---|
void |
destroy()
|
boolean |
exited()
Test if the process has exited. |
int |
exitValue()
|
InputStream |
getErrorStream()
|
InputStream |
getInputStream()
|
OutputStream |
getOutputStream()
|
int |
ID()
Get the Process ID that uniquely identifies the system process. |
int |
waitFor()
|
int |
waitFor(long timeout)
Wait for the process to exit up to a maximum timeout. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final String ID
Constructor Detail |
---|
public UNIX_Process(Process process) throws NoSuchFieldException, SecurityException
process
- The Process object obtained from a ProcessBuilder's
start method or a Runtime exec method.
NoSuchFieldException
- If the process does not have one
of the expected field variables. This will occur if the process
is not implemented by a JFC UNIXProcess or the implementation has
changed from what is expected.
SecurityException
- If a JVM SecurityManager prevents
access to the private field values of the process object.ProcessBuilder
,
Runtime
Method Detail |
---|
public OutputStream getOutputStream()
getOutputStream
in class Process
public InputStream getInputStream()
getInputStream
in class Process
public InputStream getErrorStream()
getErrorStream
in class Process
public int waitFor() throws InterruptedException
waitFor
in class Process
InterruptedException
public int exitValue()
exitValue
in class Process
public void destroy()
destroy
in class Process
public int ID()
public int waitFor(long timeout) throws InterruptedException, IOException
Causes the current thread to wait, if necessary, until the
process represented by this Process
object has
terminated or the timeout period has expired. This method returns
immediately if the subprocess has already terminated. If the
subprocess has not yet terminated, the calling thread will be
blocked. If the subprocess exits while the thread is blocked
the exit status of the subprocess will be returned. If the timeout
period expires while the thread is blocked an IOException will
be thrown.
timeout
- The maximum amount of time, in milliseconds,
to wait on subprocess exit. Wait forever if the value is <= 0
(the same as the waitFor()
method}.
InterruptedException
- If the current thread is interrupted
by another thread while it is
waiting, then the wait is ended and an InterruptedException is
thrown.
IOException
- If the timeout occurred before the process
exit occurred.public boolean exited()
The running/exited flag will only be set true after the forked process has exited.
This method tests the value of the UNIXProcess flag. The Process API
may be used to determine if the process has exited via the exitValue()
method which will throw an IllegalThreadStateException
if the process has not yet exited.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |