org.zeroturnaround.process
Class WindowsProcess

java.lang.Object
  extended by org.zeroturnaround.process.AbstractProcess
      extended by org.zeroturnaround.process.PollingProcess
          extended by org.zeroturnaround.process.PidProcess
              extended by org.zeroturnaround.process.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.


Field Summary
 
Fields inherited from class org.zeroturnaround.process.PidProcess
pid
 
Fields inherited from class org.zeroturnaround.process.AbstractProcess
log
 
Constructor Summary
WindowsProcess(int pid)
           
 
Method Summary
 void destroy(boolean forceful)
          Destroys the process handled by this killer either forcefully or gracefully according to the given option.
 boolean isAlive()
          Tests whether this process is alive.
 boolean isGracefulDestroyEnabled()
           
 boolean isIncludeChildren()
           
 void setGracefulDestroyEnabled(boolean gracefulDestroyEnabled)
           
 void setIncludeChildren(boolean includeChildren)
           
 boolean taskkill(boolean forceful)
          Sends the destroy signal to this process.
 
Methods inherited from class org.zeroturnaround.process.PidProcess
getDescription, getPid
 
Methods inherited from class org.zeroturnaround.process.PollingProcess
getIntervalForCheckingFinished, setIntervalForCheckingFinished, waitFor
 
Methods inherited from class org.zeroturnaround.process.AbstractProcess
destroyForcefully, destroyGracefully, toString, waitFor
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

WindowsProcess

public WindowsProcess(int pid)
Method Detail

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 also take some time to finish.

Returns:
true if this process is alive, false if it is finished or not found.
Throws:
IOException
InterruptedException

destroy

public void destroy(boolean forceful)
             throws IOException,
                    InterruptedException
Description copied from class: AbstractProcess
Destroys the process handled by this killer 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
InterruptedException

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
InterruptedException


Copyright © 2015 ZeroTurnaround. All rights reserved.