Simplify the termination logic and distinguish between the grunt task ending and the child process ending