ow2-proactive / scheduling

Multi-platform Scheduling and Workflows Engine
http://www.activeeon.com/workflows-scheduling
GNU Affero General Public License v3.0
62 stars 54 forks source link

In RunAsMe mode, processes spawned from a task are not killed by the ProcessTreeKiller #2776

Open fviale opened 7 years ago

fviale commented 7 years ago

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.

tobwiens commented 7 years ago

The kill_process_tree.sh script has the right to kill the spawned processes and should do it.

fviale commented 7 years ago

This would work in linux only, and will not allow killing of processes started with nohup

fviale commented 7 years ago

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 ?

fviale commented 7 years ago

We should guaranty that the process tree is killed, but not necessarily that background processes started from the task are killed.

tobwiens commented 7 years ago

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.

fviale commented 7 years ago

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.