int wait_for_child_process_exit()

in native/exec_pty.c [208:230]


int wait_for_child_process_exit(pid_t child_pid) {
    int status;
    while (waitpid(child_pid, &status, 0) < 0) {
        switch (errno) {
            case ECHILD:
                return 0;
            case EINTR:
                break;
            default:
                return -1;
        }
    }
    if (WIFEXITED(status)) {
        // The process exited normally; get its exit code.
        return WEXITSTATUS(status);
    }
    if (WIFSIGNALED(status)) {
        // The child exited because of a signal. Return 128 + signal number as all Unix shells do.
        // https://tldp.org/LDP/abs/html/exitcodes.html
        return 128 + WTERMSIG(status);
    }
    return status; // Unknown exit code; pass it as is.
}