Class ProcessUtil

java.lang.Object
io.smallrye.common.process.ProcessUtil

public final class ProcessUtil extends Object
A collection of useful process-related utility methods.
  • Method Details

    • nativeCharset

      public static Charset nativeCharset()
      Returns the native character set (not null).
      Returns:
      the native character set (not null)
    • destroyAllForcibly

      public static void destroyAllForcibly(ProcessHandle handle)
      Forcibly destroy the process and all of its descendants.
      Parameters:
      handle - the root-most process handle
    • destroyAllForcibly

      public static void destroyAllForcibly(Process process)
      Forcibly destroy the process and all of its descendants.
      Parameters:
      process - the root-most process
    • pathOfCommand

      public static Optional<Path> pathOfCommand(Path path)
      Get the absolute path of a command at the given path. If the path is relative, then the location of the executable is determined in a platform-specific manner (typically by reading the PATH environment variable). If the path is absolute, it is returned if the target file is executable.
      Parameters:
      path - the command to locate (must not be null)
      Returns:
      the optional path of the executable, or the empty optional if there is no such path (not null)
    • searchPath

      public static List<Path> searchPath()
      Returns the system search path (i.e. the PATH environment variable) as a list of Path (not null).
      Returns:
      the system search path (i.e. the PATH environment variable) as a list of Path (not null)
    • pathOfJava

      public static Path pathOfJava()
      Returns the Path of the current Java executable (not null). The returned path may be absolute, or it may be relative to the current PATH of this process. If the path cannot be determined, a relative path containing nameOfJava() is returned.
      Returns:
      the Path of the current Java executable (not null)
    • javaHome

      public static Optional<Path> javaHome()
      Returns the path corresponding to java.home or the JAVA_HOME environment variable, if any.
      Returns:
      the path corresponding to java.home or the JAVA_HOME environment variable, if any
    • nameOfJava

      public static String nameOfJava()
      Returns the name of the standard Java executable on this OS (not null).
      Returns:
      the name of the standard Java executable on this OS (not null)
    • stillRunningAfter

      public static boolean stillRunningAfter(Process proc, long nanos)
      Wait (uninterruptibly) for some amount of time for the given process to finish.
      Parameters:
      proc - the process (must not be null)
      nanos - the number of nanoseconds to wait
      Returns:
      true if the process is still running after the elapsed time, or false if it has exited
    • stillRunningAfter

      public static boolean stillRunningAfter(Process proc, Duration time)
      Wait (uninterruptibly) for some amount of time for the given process to finish.
      Parameters:
      proc - the process (must not be null)
      time - the amount of time to wait (must not be null)
      Returns:
      true if the process is still running after the elapsed time, or false if it has exited
    • stillRunningAfter

      public static boolean stillRunningAfter(ProcessHandle proc, long nanos)
      Wait (uninterruptibly) for some amount of time for the given process to finish.
      Parameters:
      proc - the process handle (must not be null)
      nanos - the number of nanoseconds to wait
      Returns:
      true if the process is still running after the elapsed time, or false if it has exited