Avoid waiting forever

If the process "pid" is already terminated by the time "waitpid" is called for the first time, then "done" is never going to be true.