fix to wait for terminated subprocess