0

When I close my process via the command "ctrl c" in console my process is closed in the right way. But when I just close console or just rebooting the system ( all the time with the ongoing process ) my process is closed in a bad way (some file are no closed or computer still displays a restart screen...How can I catch this exception? (When the process is killed) or how to fix this issue?

EDIT (some of code) : I created processes via another proces like this :

processBuilder = new ProcessBuilder(
            "java", "-jar",
            pathToJar,
            user,
            password,
    );
    processBuilder.redirectOutput(ProcessBuilder.Redirect.INHERIT);
    processBuilder.redirectError(ProcessBuilder.Redirect.INHERIT);
    try {
        process = processBuilder.start();
    } catch (IOException e) {
        e.printStackTrace();
    }

and I stop the process like this :

        process.destroy();
    try {
        process.waitFor(5, TimeUnit.SECONDS);
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
    if (process.isAlive())
        try {
            Thread.sleep(5000L);

        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    process.destroyForcibly();

When I do this programmatically or via command "ctr c" in console everything is okay. But I have trouble when it happened by rebooting system or just closing console.

M. Lup
  • 5
  • 6

0 Answers0