Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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 "); } 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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Intelligent Databases Technologies And Applications

Authors: Zongmin Ma

1st Edition

1599041219, 978-1599041216

More Books

Students also viewed these Databases questions

Question

=+Which associations exist?

Answered: 1 week ago

Question

Write short notes on departmentation.

Answered: 1 week ago

Question

What are the factors affecting organisation structure?

Answered: 1 week ago

Question

What are the features of Management?

Answered: 1 week ago

Question

Briefly explain the advantages of 'Management by Objectives'

Answered: 1 week ago