Question
Modify the programs Project1A.c and Project1B.c so that the result will support your answer to the question: 1. VARIABLES: Are any of the variables of
Modify the programs Project1A.c and Project1B.c so that the result will support your answer to the question:
1. VARIABLES: 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. FILE DESCRIPTORS: 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. EXIT/WAIT: 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. TERMINATOR: 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?
TERMINATOR 2: 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 "); } else { pid2 = fork(); if (pid2 == 0) { // 2nd child process printf("Child process A2 created "); } 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; }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started