Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I. Compile and execute the following programming exercises: Figure 3 . 3 0 : Program shows that value modification by child doesn't affect value for

I. Compile and execute the following programming exercises:
Figure 3.30 : Program shows that value modification by child doesn't affect value for parent process. Print the content of the global variable 'value' in child and parent.
Figure 3.31 : Program shows that 8 processes are created. Add a print statement after each fork().
Figure 3.32(Fig 3.21 in some books) : Program shows that 16 total processes are created. Display their 'pid's.
Figure 3.33(Fig 3.22 in some books): Program shows that "LINE J" after call to 'execlp()' will not be printed if execlp() is successful.
Figure 3.34(Fig 3.23 in some books) : Program shows the outputs at lines A, B, C, and D.
Figure 3.35(Fig 3.24 in some books): Programs show the outputs at lines X and Y.
________________________________________________________________________
Example of adding print statements to display process id in Figure 3.32:
#include
#include
#include
int main()
{
int i;
for (i=0; i<3; i++)
{
fork();
if (i ==0) printf("Loop 0: hello from %d
", getpid());
if (i ==1) printf("\tLoop 1 hello from %d
", getpid());
if (i ==2) printf("\t\tLoop 2: hello from %d
", getpid());
}
return 0;
}
_____________________________________________________________________________________________________________
II. Zombie & Orphan Processes
Zombie Process
When a child process terminates, an association with its parent survives until the parent in turn either:
calls wait() or
terminates normally
The child process entry in the process table is therefore not freed up immediately. Although no longer active, the child process is still in the system because the exit code needs to be stored in case the parent subsequently calls wait(). The child becomes what is known as defunct, or a zombie process.
Orphan Process
If a parent process did not invoke wait () and instead terminated, its child processes remain as orphan processes
Compile and execute fork1.c program. The original process (the parent) finishes before the child has printed all of its messages, so the next shell prompt appears mixed in with the output. Does the child become an orphan? Why or why not?
Convert the fork1.c program to a zombie process. (Hint: change the number of messages. If the child prints fewer messages than the patent, child will finish first and will exist as a zombie until the parent has finished.)
______________________________________________________________________________________________________________
III. Submit the screenshots of the compilation, execution, and results.
If you get "warning: implicit declaration of function 'wait' " change #include to #include
Do not submit the source codes. Points will be deducted, if instructions are not followed.
Submit all screenshots on a single file, sequentially numbered.

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

A Complete Guide To Data Science Essentials

Authors: Miguel

1st Edition

9358684992, 978-9358684995

More Books

Students also viewed these Databases questions

Question

1. How might volunteering help the employer and the employee?

Answered: 1 week ago