Package jnr.process

Class Process


  • public class Process
    extends java.lang.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.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      long exitValue()
      Get the exit code from the child process, or raise IllegalThreadStateException 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.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • 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 raise IllegalThreadStateException if it has not yet terminated.
        Returns:
        the exit value from the terminated child process