Improve waitpid error handling