Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Solved with the explanation please Consider the following code #include #include

ID: 3846237 • Letter: S

Question

Solved with the explanation please

Consider the following code

#include

#include

void main(void) {

pid_t pid; int i=0;

pid = fork();

if (pid==0)

pid = getpid();

else if (pid>0)

            i=5;

else if (pid<0)

                        i=10;

return 0; }

What are the values of i and pid:

a)If the fork() is successful and returned in the child process:

b)If the fork() is successful and returned in the parent process:

c)If the fork() is unsuccessful:

-----------------------------------------------------

In a multiprogramming environment, consider we have the following process P1:

#

Instruction

Execution time

1

Assignment

2 ms

2

Fork ()

3 ms

3

Wait (Null)

3 ms

4

Print

2ms

Assume the following:

fork () is executed correctly.

Push time in any queue =2 ms.

Wait time in printer queue =4 ms.

Dispatch time = 1ms.

Complete the following table:

Accumulative

Time

Process

State

Executing

Instruction

Queue

Name

Execution

Time

Dispatch Time

Push

Time

Wait

Time in Q

0

Ready

Ready Q

1

1

#

Instruction

Execution time

1

Assignment

2 ms

2

Fork ()

3 ms

3

Wait (Null)

3 ms

4

Print

2ms

Explanation / Answer

values of i and pid are:
a) child: i=0; pid= 4614
b) parent: i=5; pid = 4614 (it can be any positive value)
c) i=10 (because pid will be negative value)
pid= -123 (can be any negative number)

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote