Process class in Java

java.lang.Process

The process provides control of native processes started by ProcessBuilder.start and Runtime.exec. The class provides methods for performing input from the process, performing output to the process, waiting for the process to complete, checking the exit status of the process, and destroying (killing) the process.

The ProcessBuilder.start() and Runtime.exec methods create a native process and return an instance of a subclass of Process that can be used to control the process and obtain information about it.

The methods that create processes may not work well for special processes on certain native platforms, such as native windowing processes, daemon processes, Win16/DOS processes on MicrosoftWindows, or shell scripts.

Some methods of Process class

children()This method returns a snapshot of the direct children of the process. The parent of a direct child process is the process. Typically, a process that is not alive has no children.

descendants()This method returns a snapshot of the descendants of the process.

destroy()This method kills the process.

destroyForcibly()This method kills the process forcibly. The process represented by this Process object is forcibly terminated.

exitValue()This method returns the exit value for the process.

getErrorStream()This method returns the input stream connected to the error output of the process.

getInputStream()This method returns the input stream connected to the normal output of the process.

getOutputStream()This method returns the output stream connected to the normal input of the process.

info()This method returns a snapshot of information about the process.

isAlive()This method tests whether the process represented by this Process is alive.

onExit()This method returns a CompletableFuture<Process> for the termination of the Process.

pid()This method returns the native process ID of the process.

supportsNormalTermination()This method returns true if the implementation of destroy is to normally terminate the process, Returns false if the implementation of destroy forcibly, and immediately terminates the process.

toHandle()This method returns a ProcessHandle for the Process.

waitFor()This method causes the current thread to wait, if necessary until the process represented by this Process object has terminated. This method returns immediately if the process has already been terminated.

waitFor(long, TimeUnit)This method takes two arguments. This method causes the current thread to wait, if necessary until the process represented by this Process object has terminated, or the specified waiting time elapses.

No comments:

Post a Comment