Kill child process before task process.

When you killed a task, you first closed the task before killing its children and therefore their were not closed.
Now I act in the other way, by killing the children before.