Class WindowsProcess

All Implemented Interfaces:
SystemProcess

public class WindowsProcess extends PidProcess
Process implementation for Windows PID values.

It uses wmic for checking the process status and taskkill command for destroying the process.

Although the taskkill command officially supports killing both forcefully or gracefully we expect it to fail killing anything gracefully by default and we throw UnsupportedOperationException. To enable this operation call setGracefulDestroyEnabled(boolean) with true first.

  • Constructor Details

    • WindowsProcess

      public WindowsProcess(int pid)
    • WindowsProcess

      public WindowsProcess(int pid, File wmicPath)
  • Method Details

    • getWmicPath

      public File getWmicPath()
    • setWmicPath

      public void setWmicPath(File wmicPath)
    • isGracefulDestroyEnabled

      public boolean isGracefulDestroyEnabled()
    • setGracefulDestroyEnabled

      public void setGracefulDestroyEnabled(boolean gracefulDestroyEnabled)
    • isIncludeChildren

      public boolean isIncludeChildren()
    • setIncludeChildren

      public void setIncludeChildren(boolean includeChildren)
    • isAlive

      public boolean isAlive() throws IOException, InterruptedException
      Description copied from interface: SystemProcess
      Tests whether this process is alive.

      This operation may take some time to finish.

      Returns:
      true if this process is alive, false if it is finished or not found.
      Throws:
      IOException - on IO error.
      InterruptedException - if interrupted.
    • destroy

      public void destroy(boolean forceful) throws IOException, InterruptedException
      Description copied from class: AbstractProcess
      Destroys the process either forcefully or gracefully according to the given option.

      Note: The process may not terminate at all. i.e. isAlive() may return true for a any period after destroy() is called. This method may be chained to waitFor() if needed.

      No error is thrown if the process was already terminated.

      Specified by:
      destroy in class AbstractProcess
      Parameters:
      forceful - true if the process must be destroyed forcefully (like kill -KILL), false if it must be destroyed gracefully (like kill -TERM).
      Throws:
      IOException - on IO error.
      InterruptedException - if interrupted.
    • taskkill

      public boolean taskkill(boolean forceful) throws IOException, InterruptedException
      Sends the destroy signal to this process.
      Parameters:
      forceful - true if this process should be destroyed forcefully.
      Returns:
      true if this process got the signal, false if the process was not found (any more).
      Throws:
      IOException - on IO error.
      InterruptedException - if interrupted.