Fixed wait_process() to handle cases where waitpid() fails or