代码中已经发生了分叉:
if (pid == 0) {
printf("I am child PID %d\n", getpid());
exit(EXIT_SUCCESS);
} else {
pid_t child;
int status;
//need wait() function that gets child pid and exit status
printf("Child PID %d terminated with return status %d\n", child, status);
}
正如代码中所评论的,我需要一个适当的等待函数来等待孩子结束并获取孩子的 PID 和由此产生的退出状态代码。谢谢!