alibaba/arthas · warning · IllegalStateException
Cannot terminate terminated process
Error message
Cannot terminate terminated process
What it means
Thrown by Process.terminate() when the internal terminate() method returns false, which happens only when the process is already in the TERMINATED state (the guard checks processStatus != TERMINATED). Terminating an already-dead process is a no-op that Arthas flags as an error.
Source
Thrown at core/src/main/java/com/taobao/arthas/core/shell/system/impl/ProcessImpl.java:244
public void toForeground(Handler<Void> completionHandler) {
if (processStatus == ExecStatus.RUNNING) {
if (!processForeground) {
updateStatus(ExecStatus.RUNNING, null, true, foregroundHandler, terminatedHandler, completionHandler);
}
} else {
throw new IllegalStateException("Cannot set to foreground a process in " + processStatus + " state");
}
}
@Override
public void terminate() {
terminate(null);
}
@Override
public void terminate(Handler<Void> completionHandler) {
if (!terminate(-10, completionHandler, null)) {
throw new IllegalStateException("Cannot terminate terminated process");
}
}
private synchronized boolean terminate(int exitCode, Handler<Void> completionHandler, String message) {
if (processStatus != ExecStatus.TERMINATED) {
//add status message
this.appendResult(new StatusModel(exitCode, message));
if (process != null) {
processOutput.close();
}
updateStatus(ExecStatus.TERMINATED, exitCode, false, endHandler, terminatedHandler, completionHandler);
if (process != null) {
process.unregister();
}
return true;
} else {
return false;
}View on GitHub (pinned to 21cf2e9ba5)
Solutions
- Check job status before terminating — ignore TERMINATED jobs.
- Wrap kill in a try-catch for IllegalStateException and treat it as already-done.
Example fix
// before
job.process().terminate();
// after
if (job.process().status() != ExecStatus.TERMINATED) {
job.process().terminate();
} Defensive patterns
Strategy: type-guard
Validate before calling
if (process.status() != ExecStatus.TERMINATED) {
process.terminate();
} Type guard
boolean canTerminate(Process p) {
return p.status() != ExecStatus.TERMINATED;
} Try / catch
try {
process.terminate();
} catch (IllegalStateException e) {
if (e.getMessage().contains("Cannot terminate terminated")) {
// already dead; safe to ignore
}
} Prevention
- Check process status before terminating.
- Treat double-terminate as benign in automation by catching IllegalStateException.
When it happens
Trigger: Calling terminate() (or 'kill <jobId>') on a job whose process has already finished and transitioned to TERMINATED.
Common situations: Double-kill in automation. User presses Ctrl+C or runs kill on a job that already completed naturally.
Related errors
- Cannot interrupt process in {} state
- Cannot resume process in {} state
- Cannot suspend process in {} state
- Cannot set to background a process in {} state
- Cannot set to foreground a process in {} state
AI-assisted analysis of alibaba/arthas@21cf2e9ba5 (2026-08-14).
Data as JSON: /api/errors/4357d0a5f67f1399.
Report an issue: GitHub.