Package jnr.process

Class Process

java.lang.Object
jnr.process.Process

public class Process extends Object
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
    Modifier and Type
    Field
    Description
    private final jnr.enxio.channels.NativeDeviceChannel
     
    (package private) long
     
    private final jnr.enxio.channels.NativeDeviceChannel
     
    private final jnr.enxio.channels.NativeDeviceChannel
     
    private final long
     
    private final jnr.posix.POSIX
     
  • 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

    Modifier and Type
    Method
    Description
    long
    Get the exit code from the child process, or raise IllegalThreadStateException if it has not yet terminated.
    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).
    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.
    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
    Get the pid of the child process.
    int
    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
    Wait for the subprocess to terminate and return its exit code.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • 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-posix
      pid - the subprocesses's pid
      out - 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

      public 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 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 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 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 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 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 raise IllegalThreadStateException if it has not yet terminated.
      Returns:
      the exit value from the terminated child process