Putting waitpid in while