How can I kill processes in Java without forcing them?

I have a Java program that runs a number of other programs. Once the user is finished, they have a button to kill all the processes, this should kill everything that works, but it should do it with their forced. At least one of these other processes is also written in Java and has several stops because it automatically saves the settings file on exit and kills the processes that it started itself, for example.

    Runtime.getRuntime().addShutdownHook(new Thread() {
      public void run() {
        if (process != null)
            process.destroy();
      }
    }

When the main process calls are destroyed, the above code does not run in the subprocess. Is there anyway that I can terminate the processes so that it still executes?

I port with Perl, which will kill (9, @kill_process);

Thanks.

+3
2

Kill 9 (SIGKILL) , . , , - .

process.destroy() Perl kill(9,@kill_process);, .

Kill 15 (SIGTERM) , .

+6

. . kill. Perl, , .

, , os. - HUP. , " " ( , ), . .

9 ( , Perl), .

, , . , "Ctrl + c" "Alt + f4" ( ) STDIN .

+2

Source: https://habr.com/ru/post/1715993/


All Articles