Package jnr.process
Class Process
- java.lang.Object
-
- jnr.process.Process
-
public class Process extends java.lang.Object
AProcess
look-alike based on the Java Native Runtime's native FFI binding. Note this adds thegetIn()
,getOut()
, andgetErr()
methods for accessing selectable channels from the child process, as well askillProcessGroup()
to kill the child and descendants.
-
-
Constructor Summary
Constructors Constructor Description Process(jnr.posix.POSIX posix, long pid, int out, int in, int err)
Construct a new Process instance that wraps the given pid and native IO streams.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description long
exitValue()
Get the exit code from the child process, or raiseIllegalThreadStateException
if it has not yet terminated.java.nio.channels.SelectableChannel
getErr()
Get the selectable channel for the error stream (input for parent, error output for child).java.io.InputStream
getErrorStream()
Get the stream for the error stream (input for parent, error output for child).java.nio.channels.SelectableChannel
getIn()
Get the selectable channel for the parent's input, which is the child's output.java.io.InputStream
getInputStream()
Get the stream for the parent's input, which is the child's output.java.nio.channels.SelectableChannel
getOut()
Get the selectable channel for the parent's output, which is the child's input.java.io.OutputStream
getOutputStream()
Get the stream for the parent's output, which is the child's input.long
getPid()
Get the pid of the child process.int
kill()
Kill the child process with a KILL signal.int
kill(jnr.constants.platform.Signal sig)
Kill the child process with the specified signal.int
killProcessGroup()
Kill the child process and all its descendants with a KILL signal.int
killProcessGroup(jnr.constants.platform.Signal sig)
Kill the child process and all its descendants with the specified signal.long
waitFor()
Wait for the subprocess to terminate and return its exit code.
-
-
-
Constructor Detail
-
Process
Process(jnr.posix.POSIX posix, long pid, int out, int in, int err)
Construct a new Process instance that wraps the given pid and native IO streams.- Parameters:
posix
- the POSIX instance from jnr-posixpid
- the subprocesses's pidout
- the parent's output stream (subprocess's input stream)in
- the parent's input stream (subprocess's output stream)err
- the parent's error input stream (subprocess's error output stream)
-
-
Method Detail
-
getPid
public long getPid()
Get the pid of the child process.- Returns:
- the pid of the child process
-
getOut
public java.nio.channels.SelectableChannel getOut()
Get the selectable channel for the parent's output, which is the child's input.- Returns:
- the parent's output channel for the child's input
-
getOutputStream
public java.io.OutputStream getOutputStream()
Get the stream for the parent's output, which is the child's input.- Returns:
- the parent's output stream for the child's input
-
getIn
public java.nio.channels.SelectableChannel getIn()
Get the selectable channel for the parent's input, which is the child's output.- Returns:
- the parent's input channel for the child's output
-
getInputStream
public java.io.InputStream getInputStream()
Get the stream for the parent's input, which is the child's output.- Returns:
- the parent's input stream for the child's output
-
getErr
public java.nio.channels.SelectableChannel getErr()
Get the selectable channel for the error stream (input for parent, error output for child).- Returns:
- the parent's error input channel for the child's error output
-
getErrorStream
public java.io.InputStream getErrorStream()
Get the stream for the error stream (input for parent, error output for child).- Returns:
- the parent's error input stream for the child's error output
-
waitFor
public long waitFor()
Wait for the subprocess to terminate and return its exit code.- Returns:
- the exit code from the child process, after it has terminated
-
kill
public int kill()
Kill the child process with a KILL signal.- Returns:
- the return code from the native kill function
-
kill
public int kill(jnr.constants.platform.Signal sig)
Kill the child process with the specified signal.- Parameters:
sig
- the signal to send to the child process- Returns:
- the return code from the native kill function
-
killProcessGroup
public int killProcessGroup()
Kill the child process and all its descendants with a KILL signal.- Returns:
- the return code from the native kill function
-
killProcessGroup
public int killProcessGroup(jnr.constants.platform.Signal sig)
Kill the child process and all its descendants with the specified signal.- Parameters:
sig
- the signal to send to the child and its descendants- Returns:
- the return code from the native kill function
-
exitValue
public long exitValue()
Get the exit code from the child process, or raiseIllegalThreadStateException
if it has not yet terminated.- Returns:
- the exit value from the terminated child process
-
-