I have a Java program that runs a number of other programs. Once the user is finished they have a button to kill all processes, this should kill everything that is running but it should do it with forcing them. At least one of these other processes is also written in Java and has a number of shutdown hooks as it automatically saves a preferences file on exit and kills processes it has started itself, such as.
Runtime.getRuntime().addShutdownHook(new Thread() {
public void run() {
if (process != null)
process.destroy();
}
}
When the main process calls destroy the above code is not run on the subprocess. Is there anyway that I can terminate the processes so this will still run?
I am porting from Perl which does it will the kill(9,@kill_process);
Thanks.
Kill signal 9 (SIGKILL) tells the operating system to kill the process. The process gets no notification in advance that this is going to happen and cannot do any cleanup because of it.
process.destroy() is the equivalent of Perl’s
kill(9,@kill_process);, and your old process wouldn’t have been doing any cleanup either.Kill signal 15 (SIGTERM) will tell a process to kill itself.