public class KillableProcessHandler extends OSProcessHandler implements KillableProcess
KillableProcessHandler
).
At first "stop" button send SIGINT signal to process, if it still hangs user can terminate it recursively with SIGKILL signal.
Soft kill works on Unix, and also on Windows if a mediator process was used.
OSProcessHandler.Silent
BaseOSProcessHandler.SimpleOutputReader
myCharset, myCommandLine, myPresentableName, myProcess, myWaitFor
SILENTLY_DESTROY_ON_CLOSE, TERMINATION_REQUESTED
Constructor and Description |
---|
KillableProcessHandler(GeneralCommandLine commandLine) |
KillableProcessHandler(GeneralCommandLine commandLine,
boolean withMediator)
|
KillableProcessHandler(java.lang.Process process,
java.lang.String commandLine)
commandLine must not be not empty (for correct thread attribution in the stacktrace) |
KillableProcessHandler(java.lang.Process process,
java.lang.String commandLine,
java.nio.charset.Charset charset)
commandLine must not be not empty (for correct thread attribution in the stacktrace) |
KillableProcessHandler(java.lang.Process process,
java.lang.String commandLine,
java.nio.charset.Charset charset,
java.util.Set<? extends java.io.File> filesToDelete)
commandLine must not be not empty (for correct thread attribution in the stacktrace) |
Modifier and Type | Method and Description |
---|---|
boolean |
canKillProcess() |
protected boolean |
destroyProcessGracefully() |
protected void |
destroyProcessImpl()
Performs process destruction.
|
protected void |
doDestroyProcess() |
void |
killProcess() |
protected static GeneralCommandLine |
mediate(GeneralCommandLine commandLine,
boolean withMediator,
boolean showConsole) |
protected void |
notifyProcessTerminated(int exitCode) |
void |
setShouldKillProcessSoftly(boolean shouldKillProcessSoftly)
Sets whether the process will be terminated gracefully.
|
void |
setShouldKillProcessSoftlyWithWinP(boolean shouldKillProcessSoftlyWithWinP)
Enables sending Ctrl+C to a Windows-process on first termination attempt.
|
boolean |
shouldKillProcessSoftly() |
checkEdtAndReadAction, deleteFileOnTermination, getDefaultModality, killProcessTree, onOSProcessTerminated, processCanBeKilledByOS, processHasSeparateErrorStream, readerOptions, setHasPty, setShouldDestroyProcessRecursively, shouldDestroyProcessRecursively, waitFor, waitFor
createErrorDataReader, createOutputDataReader, createProcessErrReader, createProcessOutReader, executeOnPooledThread, executeTask, startNotify, toString
closeStreams, detachIsDefault, detachProcessImpl, getCharset, getCommandLine, getProcess, getProcessInput
addProcessListener, addProcessListener, destroyProcess, detachProcess, getExitCode, isProcessTerminated, isProcessTerminating, isSilentlyDestroyOnClose, isStartNotified, notifyProcessDetached, notifyTextAvailable, removeProcessListener
changeUserMap, clearUserData, clone, copyCopyableDataTo, copyUserDataTo, getCopyableUserData, getUserData, getUserDataString, getUserMap, isUserDataEmpty, putCopyableUserData, putUserData, putUserDataIfAbsent, replace, setUserMap
public KillableProcessHandler(GeneralCommandLine commandLine) throws ExecutionException
ExecutionException
public KillableProcessHandler(GeneralCommandLine commandLine, boolean withMediator) throws ExecutionException
ExecutionException
public KillableProcessHandler(java.lang.Process process, java.lang.String commandLine)
commandLine
must not be not empty (for correct thread attribution in the stacktrace)public KillableProcessHandler(java.lang.Process process, java.lang.String commandLine, java.nio.charset.Charset charset)
commandLine
must not be not empty (for correct thread attribution in the stacktrace)public KillableProcessHandler(java.lang.Process process, java.lang.String commandLine, java.nio.charset.Charset charset, java.util.Set<? extends java.io.File> filesToDelete)
commandLine
must not be not empty (for correct thread attribution in the stacktrace)protected static GeneralCommandLine mediate(GeneralCommandLine commandLine, boolean withMediator, boolean showConsole)
public boolean shouldKillProcessSoftly()
public void setShouldKillProcessSoftly(boolean shouldKillProcessSoftly)
shouldKillProcessSoftly
- true, if graceful process termination should be attempted first (i.e. soft kill)protected void destroyProcessImpl()
ProcessHandler
This is an internal implementation of ProcessHandler.destroyProcess()
. All sub-classes must implement this method and perform the
destruction in this method. This method is called from ProcessHandler.destroyProcess()
and it can be in any thread including the
event dispatcher thread. You should avoid doing any expensive operation directly in this method. Instead, you may post the work to
background thread and return without waiting for it. If the performed destruction led to process termination,
ProcessHandler.notifyProcessTerminated(int)
must be called in any thread (not necessary from this method).
destroyProcessImpl
in class BaseProcessHandler<java.lang.Process>
protected void notifyProcessTerminated(int exitCode)
notifyProcessTerminated
in class ProcessHandler
protected void doDestroyProcess()
doDestroyProcess
in class OSProcessHandler
public void setShouldKillProcessSoftlyWithWinP(boolean shouldKillProcessSoftlyWithWinP)
shouldKillProcessSoftlyWithWinP
- true to useprotected boolean destroyProcessGracefully()
public boolean canKillProcess()
canKillProcess
in interface KillableProcess
public void killProcess()
killProcess
in interface KillableProcess