Package jnr.process
Class Process
java.lang.Object
jnr.process.Process
A
Process
look-alike based on the Java Native Runtime's native FFI binding.
Note this adds the getIn()
, getOut()
, and getErr()
methods for accessing selectable
channels from the child process, as well as killProcessGroup()
to kill the child and descendants.-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionProcess
(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
Modifier and TypeMethodDescriptionlong
Get the exit code from the child process, or raiseIllegalThreadStateException
if it has not yet terminated.getErr()
Get the selectable channel for the error stream (input for parent, error output for child).Get the stream for the error stream (input for parent, error output for child).getIn()
Get the selectable channel for the parent's input, which is the child's output.Get the stream for the parent's input, which is the child's output.getOut()
Get the selectable channel for the parent's output, which is the child's input.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
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.
-
Field Details
-
pid
private final long pid -
posix
private final jnr.posix.POSIX posix -
out
private final jnr.enxio.channels.NativeDeviceChannel out -
in
private final jnr.enxio.channels.NativeDeviceChannel in -
err
private final jnr.enxio.channels.NativeDeviceChannel err -
exitValue
long exitValue
-
-
Constructor Details
-
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 Details
-
getPid
public long getPid()Get the pid of the child process.- Returns:
- the pid of the child process
-
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
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
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
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
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
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
-