0% found this document useful (0 votes)
48 views

Answers - Test 2: P1 P2 P3 P4

This document contains the answers to test questions on processes and resource allocation. 1. It provides the answers to multiple choice questions on a test. 2. It includes a resource allocation problem showing the allocation, available resources, and need matrix for 4 processes (P1, P2, P3, P4) requesting resources from 4 resources (R1, R2, R3, R4). 3. It poses additional questions about determining the need matrix from the allocation, whether specific process requests would be granted, and explaining the solutions to mutual exclusion and critical section problems.

Uploaded by

Harshita Gopu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
48 views

Answers - Test 2: P1 P2 P3 P4

This document contains the answers to test questions on processes and resource allocation. 1. It provides the answers to multiple choice questions on a test. 2. It includes a resource allocation problem showing the allocation, available resources, and need matrix for 4 processes (P1, P2, P3, P4) requesting resources from 4 resources (R1, R2, R3, R4). 3. It poses additional questions about determining the need matrix from the allocation, whether specific process requests would be granted, and explaining the solutions to mutual exclusion and critical section problems.

Uploaded by

Harshita Gopu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 3

Answers Test 2

Question 1
Q
Ans
Q
1
B
8
2
B
9
3
B
10
4
C
11
5
B
12
6
B
13
7
B
14
15
16

Ans
C
C
B
B
B
B
B
B
65536

Question 2
Process

P1
P2
P3
P4

Allocation
R1 R2 R3 R4
1 0 2 1
2 0 1 1
1 1 0 1
1 1 1 1

Max

Available

R1 R2 R3 R4
1 1 2 1
2 2 2 1
2 1 3 1
1 1 2 2

R1 R2 R3 R4
0 0 2 1
0 0 1 0
1 1 3 2
1 0 3 2
2 1 5 3
1 1 2 3
3 2 5 4
3 0 4 4
5 2 6 5

1. What is the need matrix? Write your answer in the table below.
Process
P1
P2
P3
P4

R1
0
0
1
0

Need
R2 R3
1
0
2
1
0
3
0
1

R4
0
0
0
1

2. The above state is a safe state since all the processes can complete
according to the Safety algorithm. The safe sequence is: P4, P1, P3, P2.
3. If process P2 requests for (0,0,2,0), will this request granted? Explain your
answer.
The request of process P2 cannot be granted since the request is greater
than the need of P2.

1/3

4. If process P3 requests for (1,0,2,0), will this request granted? Explain your
answer.
The request of process P3 cannot be granted immediately since the
required resources are not available at the moment therefore, the
process should wait.
Question 3 [3+7 points]
1. Which variables should you declare as shared variable for algorithm 3 for mutual
exclusion as discussed in the class? Declare and initialize them properly.
int turn=0;
Boolean Flag[2]={False,False};

2. Consider the following two cooperating processes. One of the processes is given
below. The shared variable are x, and y.
There are two critical sections in the program. Therefore, both of them should
be taken care of. We need to put wait(s) before the critical sections and
signal(s) after the critical sections. The program should be as follows.
int main(){
int m,n,i;
/* get shared memory and attach it to your process.
Ptr points to the shared memory */
printf(Enter the value of n);
scanf(%d,&n);
wait(s)
ptr->x=1;
signal(s);
i=1;
n=5;
while(i<n) {
m=i;
wait(s);
ptr->x++
m=ptr->x+m;
ptr->y=m+1;
signal(s);
i++;
}
Printf(The job is done!!!!);
}

2/3

3/3

You might also like