Zombies and exit statuses after selective waitpid

A parent process runs the code below. Assume every fork() succeeds, the parent has not changed how SIGCHLD is handled, and all four children have terminated before the parent begins sleep(60).


C
pid_t pid[4];
for (int i = 0; i < 4; i++) {
    pid[i] = fork();
    if (pid[i] == 0)
        exit(100 * i);
}
int s1, s2;
waitpid(pid[3], &s1, 0);
waitpid(pid[0], &s2, 0);
sleep(60);


Find the number of zombie children of this parent while it sleeps, the value of WEXITSTATUS(s1), and the value of WEXITSTATUS(s2). Give each as a whole number.

Your answers

Create a free account to get started

Unlock full course notes by signing up

  • Video lessons taught by top educators
  • Practice questions with guided solutions
  • Written review notes for reference
  • Expert answers anytime from course tutors

More Concurrent Programs Questions: