Process class

java.lang
Process

java.lang.Object 
  java.lang.Process

public abstract class Process
     

extends Object

ProcessBuilder.start() The and  Runtime.exec method creates a native process and returns  Process an instance of the subclass, which can be used to control the process and obtain related information. Process The class provides methods for executing input from the process, output to the process, waiting for the process to complete, checking the exit status of the process, and destroying (killing) the process.

The method of creating processes may not work well for specific processes on certain native platforms, such as native window processes, daemon processes, Win16/DOS processes on Microsoft Windows, or shell scripts. The created child process does not have its own terminal or console. All its standard io (ie stdin, stdout, and stderr) operations will be redirected to the parent process through three streams ( getOutputStream(), getInputStream() and  getErrorStream()). The parent process uses these streams to provide input to the child process and obtain output from the child process. Because some native platforms only provide a limited buffer size for standard input and output streams, if reading and writing the output stream or input stream of the child process fails quickly, it may cause the child process to block or even cause a deadlock.

When there are no  Process more references to the object, instead of deleting the child process, it continues to execute the child process asynchronously.

For Process Java processes with  objects, there is no need to execute Process the processes represented by the objects asynchronously or concurrently  .

 

 

From the following version:

JDK1.0

See also:

ProcessBuilderRuntime.exec(String[], String[], File)


Construction method summary
Process()
           

 

Method summary
abstract  void destroy()
          Kill the child process.
abstract  int exitValue()
          Returns the exit value of the child process.
abstract  InputStream getErrorStream()
          Get the error stream of the child process.
abstract  InputStream getInputStream()
          Get the input stream of the child process.
abstract  OutputStream getOutputStream()
          Get the output stream of the child process.
abstract  int waitFor()
          Causes the current thread to wait, if necessary, until Process the process represented by the  object has terminated.

 

 Methods inherited from class java.lang. Object
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

 

Construction method details

Process

public Process()

Method details

getOutputStream

public abstract OutputStream getOutputStream()

Get the output stream of the child process. The output stream is passed to Process the standard input stream of the process represented by this  object.

Implementation note: It is a good idea to buffer the output stream.

Note: The reason why it is outputstream instead of inputstream here is because the main body of this stream has always been the main process, for the main process, the child process of process

It is equivalent to another file, so it is output to the child process

return:

The output stream connected to the normal input of the child process.


getInputStream

public abstract InputStream getInputStream()

Get the input stream of the child process. The input stream gets Process the standard output stream of the process represented by this  object.

Implementation note: It is a good idea to buffer the input stream.

Note: The input stream of the child process refers to the stream output from the child process to the main process

return:

The input stream connected to the normal output of the child process.

See also:

ProcessBuilder.redirectErrorStream()


getErrorStream

public abstract InputStream getErrorStream()

Get the error stream of the child process. The error stream obtains Process the data transmitted by the error output stream of the process represented by this  object.

Implementation note: It is a good idea to buffer the input stream.

 

return:

The input stream connected to the error stream of the child process.

See also:

ProcessBuilder.redirectErrorStream()


waitFor

public abstract int waitFor()
                     throws InterruptedException

Causes the current thread to wait, if necessary, until Process the process represented by the  object has terminated. If the child process has been terminated, this method returns immediately. If the child process is not terminated, the calling thread will be blocked until the child process exits.

 

return:

The exit value of the process. According to convention, it  0 means normal termination.

Throws:

InterruptedException -If the current thread is interrupted by another thread  while waiting, stop waiting and throw  InterruptedException.


exitValue

public abstract int exitValue()

Returns the exit value of the child process.

 

return:

Process The exit value of the child process represented by this  object. By convention, the value  0 indicates normal termination.

Throws:

IllegalThreadStateExceptionProcess -If the child process represented by  this  object has not yet terminated.


destroy

public abstract void destroy()

Kill the child process. Forcefully terminate Process the child process represented by this  object.

 


Guess you like

Origin blog.csdn.net/m0_37839403/article/details/114984585