A fork has already occurred in code:
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);
}
As commented in the code, I need an appropriate wait function that will wait for child to end and get the PID and resulting exit status code of the child. Thanks!
You can use
wait(), orwaitpid()(same page, really).Or, if you’re on BSD,
wait3(), orwait4()(but not, AFAIK,wait2()).