Open fviale opened 7 years ago
The kill_process_tree.sh script has the right to kill the spawned processes and should do it.
This would work in linux only, and will not allow killing of processes started with nohup
After some investigation, using a shutdownhook with the ProcessTreeKiller inside the forked JVM does not work, at least on windows, because it is not executed when the task is killed.
The Windows version of the processbuilder.destroy() kills the whole process tree. Maybe something similar is possible as well in linux ?
We should guaranty that the process tree is killed, but not necessarily that background processes started from the task are killed.
So the Process.destroy() calls TerminateProcess of the running Windows Program source code: http://hg.openjdk.java.net/jdk8/jdk8/jdk/file/687fd7c7986d/src/windows/native/java/lang/ProcessImpl_md.c#l435
The windows TerminateProcess handler does no execute any additional code: https://msdn.microsoft.com/en-us/library/windows/desktop/ms686722(v=vs.85).aspx
That maybe explains why no shutdownHook is executed.
Yes, that's what I thought, basically the windows version does the job, by killing the process tree, even though it does not allow graceful termination. On the other hand the kill_process_tree.sh script is maybe doing something similar with this code:
for pid in `pstree -p $ppid | grep -o -E [0-9]+`
do
echo "Send SIGKILL to $pid"
kill -9 $pid > /dev/null 2>&1
done
In which case, then it's only spawned background processes which are not killed, which is not a real issue.
This is because the ProcessTreeKiller is not executed by the forked JVM process but by the node process, which does not have the rights to kill spawned processes.