Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Process creation using fork This assignment requires you to experiment with the creation, termination and handling of processes in UNIX by writing small C programs.

image text in transcribed

Process creation using fork This assignment requires you to experiment with the creation, termination and handling of processes in UNIX by writing small C programs. First, let us make sure we can write a program using calls such as fork and exec, and get it to compile and run. Write a program X that creates two child processes Y and Z, and write a program A that creates a child process B such that the child B loads and executes the program X. To test such a program, you should make each of the processes to do some I/O (e.g. write something to the output, or wait for some input) at appropriate places. For each of the questions below, design a test experiment by modifying the programs you have written so that the result of test justifies the answer to the question Are any of the variables of a parent shared with any of its child processes? Do the children of the same parent share some variable among themselves? Are file descriptors of a parent inherited by child processes? In particular, if a file F is opened by a parent and kept open across a call to fork, is F still open in child process? If yes, when a child process reads blocks from F, will the parent remain at the same position in F? 1. 2. 3. Recall the exit and wait calls that can be used for communication between a parent and its children. Modify the program so that X terminates only after both its children have terminated. Hint: man wait() Is it allowed for a parent to terminate before one of its child processes terminates? If so, does it affect the children in any way? 4. 5. Is it possible for X to terminate its child process, say Y? Is it possible for A to terminate its grandchild Y? How? Hint: Using exit() to pass data between child and parent will not work in this case; for details about why, see man wait. For each question, first describe succinctly what you expect and how you have designed the test. Then include the code. Your code should be well documented, including the explanations to any sections which might be unclear. Finally, include the output of the test, and explain how it justifies the

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

DNA Databases

Authors: Stefan Kiesbye

1st Edition

0737758910, 978-0737758917

More Books

Students also viewed these Databases questions