Is it allowed for a parent to terminate before one of its


Please answer the following questions based on the C code for Program1A.c and Program1B.c

1. Are any of the variables of a parent shared with any of its child processes? Do the children of the same parent share some variables between themselves?

2. Are file descriptors of a parent inherited by child processes? Specifically, if a file Project1.txt is opened by a parent and kept open across a call to fork, is Project1.txt still open in the child process? If the answer is yes, when a child process reads blocks from Project1.txt, will the parent remain at the same position in Project1.txt?

3. Remember that the wait and exit calls can be used for communication between a parent process and its child processes. Now modify Project1A.c so that the parent process terminates only after BOTH its child processes have terminated.

4. Is it allowed for a parent to terminate before one of its child processes has terminated? If so, does this affect the child processes in any way?

Is it possible for the parent process in Project1A.c to terminate one of its child processes, say A1 or A2? Now, is it possible for the parent process in Project1B.c to terminate one of its grandchild processes, say A1 or A2? If so, how? Hint: Using exit to pass data between the child and parent will not work in this case. For details, see the man page for wait.

Project1A.c

#include
#include

int main()
{
pid_t pid1, pid2;
pid1 = fork();
if (pid1 == 0) { // child process
printf("Child process A1 created\n");
}
else {
pid2 = fork();
if (pid2 == 0) { // 2nd child process
printf("Child process A2 created\n");
} else{
waitpid(pid2,0,0); // wait till child process ends
waitpid(pid1,0,0); // wait till child process ends
}
}
return 0;
}

Project1B.c

#include
#include


int main()
{
pid_t pid1;
pid1 = fork();
if (pid1 == 0) { // child process
execv("Project1A",NULL); // run another process named Project1A
exit(127);
} else {
waitpid(pid1,0,0); // wait till child process ends
}

return 0;
}

Request for Solution File

Ask an Expert for Answer!!
Computer Engineering: Is it allowed for a parent to terminate before one of its
Reference No:- TGS02887467

Expected delivery within 24 Hours