``` #include <sys/wait.h> #include <unistd.h> pid_t child = fork(); if (child == 0) { _exit(7); /* 子进程以退出码7结束 */ } int status = 0; waitpid(child, &status, 0); /* 父进程回收,底层wait4 rax=61 */ if (WIFEXITED(status)) { int code = WEXITSTATUS(status); /* 从状态字解码退出码,非直接返回值 */ (void)code; /* 仅演示解码,避免未使用告警 */ } ``` 链路:`waitpid()` → glibc 置 `rax=61`(wait4),`rdi=pid`、`rsi=&status`、`rdx=options`、`r10=rusage` → 陷入后内核把对应子进程的终止状态写入用户态 `status`,释放其