1. Engineering
  2. Computer Science
  3. answer the following questions with the program a how many...

Question: answer the following questions with the program a how many...

Question details

Answer the following questions with the program.

a. How many child processes are created? Briefly explain your answer.
b. Is it possible for two child processes to be executing concurrently? Briefly explain your answer.
c. Would the program behave the same way if the if-else statements were replaced with the following? Briefly explain your answer.
if (pid == 0) { /* child process */
printf("Child ");
return 0;
}
wait(NULL);
printf("Parent ");

The information for program.

#include <stdio.h>
#include <unistd.h>
#include <sys/types.h> // For pid_t
#include <sys/wait.h> // For wait()

int main() {
   pid_t pid;

   /* fork a child process */
   pid = fork();

   if (pid == 0) { /* child process */
       printf("Child\n");
       return 0;
   }
   else { /* parent process */
       wait(NULL);
       printf("Parent\n");
   }

   /* fork a child process */
   pid = fork();

   if (pid == 0) { /* child process */
       printf("Child\n");
       return 0;
   }
   else { /* parent process */
       wait(NULL);
       printf("Parent\n");
   }
return 0;
}

Solution by an expert tutor
Blurred Solution
This question has been solved
Subscribe to see this solution