Move waitpid outside of loop in wait_for_child