Exit loop when pid is None