{"record":{"id":"e9e4a88f809157e6","repo":"alibaba/arthas","slug":"cannot-set-to-background-a-process-in-state","errorCode":null,"errorMessage":"Cannot set to background a process in {} state","messagePattern":"Cannot set to background a process in (.+?) state","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"core/src/main/java/com/taobao/arthas/core/shell/system/impl/ProcessImpl.java","lineNumber":216,"sourceCode":"            }\n        } else {\n            throw new IllegalStateException(\"Cannot suspend process in \" + processStatus + \" state\");\n        }\n    }\n\n    @Override\n    public void toBackground() {\n        toBackground(null);\n    }\n\n    @Override\n    public void toBackground(Handler<Void> completionHandler) {\n        if (processStatus == ExecStatus.RUNNING) {\n            if (processForeground) {\n                updateStatus(ExecStatus.RUNNING, null, false, backgroundHandler, terminatedHandler, completionHandler);\n            }\n        } else {\n            throw new IllegalStateException(\"Cannot set to background a process in \" + processStatus + \" state\");\n        }\n    }\n\n    @Override\n    public void toForeground() {\n        toForeground(null);\n    }\n\n    @Override\n    public void toForeground(Handler<Void> completionHandler) {\n        if (processStatus == ExecStatus.RUNNING) {\n            if (!processForeground) {\n                updateStatus(ExecStatus.RUNNING, null, true, foregroundHandler, terminatedHandler, completionHandler);\n            }\n        } else {\n            throw new IllegalStateException(\"Cannot set to foreground a process in \" + processStatus + \" state\");\n        }\n    }","sourceCodeStart":198,"sourceCodeEnd":234,"githubUrl":"https://github.com/alibaba/arthas/blob/21cf2e9ba52b305290be7223b980ff504bb9cb5b/core/src/main/java/com/taobao/arthas/core/shell/system/impl/ProcessImpl.java#L198-L234","documentation":"Thrown by Process.toBackground() when the process is not in the RUNNING state. Moving a process to background is only valid while it is actively running in the foreground; calling it on a READY, STOPPED, or TERMINATED process is a state error.","triggerScenarios":"Issuing the 'bg <jobId>' command on a job that is not currently running (e.g. it is stopped or already terminated).","commonSituations":"User backgrounds a job that was already suspended (must resume first) or that has completed.","solutions":["Check job status with 'jobs'; only background a RUNNING job.","If the job is STOPPED, resume it first (it will run in foreground) then move to background."],"exampleFix":"// before\njob.process().toBackground();\n\n// after\nif (job.process().status() == ExecStatus.RUNNING) {\n    job.process().toBackground();\n}","handlingStrategy":"type-guard","validationCode":"if (process.status() == ExecStatus.RUNNING) {\n    process.toBackground();\n}","typeGuard":"boolean canBackground(Process p) {\n    return p.status() == ExecStatus.RUNNING;\n}","tryCatchPattern":"try {\n    process.toBackground();\n} catch (IllegalStateException e) {\n    if (e.getMessage().contains(\"Cannot set to background\")) {\n        // not running; no-op\n    }\n}","preventionTips":["Check job is RUNNING before moving it to background.","Resume stopped jobs before backgrounding."],"tags":["process-state","background","lifecycle"],"backgroundTag":null,"analyzedSha":"21cf2e9ba52b305290be7223b980ff504bb9cb5b","analyzedAt":"2026-08-14T00:57:07.243Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}