Presentation is loading. Please wait.

Presentation is loading. Please wait.

ICS Principles of Operating Systems

Similar presentations


Presentation on theme: "ICS Principles of Operating Systems"— Presentation transcript:

1 ICS 143 - Principles of Operating Systems
Discussion 8 - HW3 review Joe Nash

2 Homework 3 Q1 Consider the traffic deadlock depicted in the following figure. Show that the four necessary conditions for deadlock indeed hold in this example. State a simple rule for avoiding deadlocks in this system.

3 Homework 3 Q1 Mutex - only one car in any intersection at one time
Hold-and-wait - cars hold their position while waiting to move forward No Preemption - can’t remove a car Circular wait - each car waits for the one in front of it, eventually reaching itself

4 Homework 3 Q1 B. The ‘keep clear of intersection’ rule. - cars do not enter intersection unless they can immediately exit it.

5 Homework 3 Q2 Determine if there is a deadlock. If so, indicate the processes and resources involved. Show how the deadlock can be resolved through addition of resources. If not, argue why this is the case, i.e. there is no deadlock. In either case, provide a feasible sequence of processes to show completion.

6 Homework 3 Q2 There is a deadlock involving two cycles, they are:
P3->R3->P1->R1->P3, and P3->R3->P2->R2->P4->R4 In order to finish process P3, an instance of R3 resource is needed. However, any instance of R3 resources cannot be released unless the P3 process itself is finished, thereby forming a dead lock.

7 Homework 3 Q2 Many ways to resolve deadlock by adding resources. You can add: R1, R2, R3 or R4 Example with R4: Sequence is now P4->P2->P3->P1

8 Homework 3 Q2 Consider a system having p processes, where each process needs a maximum of m instances of resource type R1. Given that there are r instances of resource type R1 in total, what is the minimum value of r as a function of p and m to ensure that the system is deadlock-free?

9 Homework 3 Q2 r ≥ p(m-1)+1

10 Homework 3 Q3 What is the content of the matrix Need? Process
Allocation Max Available A B C D P0 3 1 4 2 P1 P2 P3 P4 Process Need A B C D P0 1 P1 2 P2 3 P3 P4

11 Homework 3 Q3 Is the system in a safe state?
Yes, it is in a safe state. A safe sequence could be <P3, P0, P1, P2, P4> Process Allocation Max Available A B C D P0 3 1 4 2 P1 P2 P3 P4 Process Need A B C D P0 1 P1 2 P2 3 P3 P4

12 Homework 3 Q3 If a request from process P1 arrives for (0,0,1,0), can the request be granted immediately? Please state the reason. If after this, another request from process P4 arrives for (0,0,1,0), can this request be granted immediately? Process Allocation Max Available A B C D P0 3 1 4 2 P1 P2 P3 P4

13 Homework 3 Q3 Follow the resource request algorithm from lecture 11
Compare request to Need: (0,0,1,0) <= Need_1 = (0,1,1,2), satisfied. Compare request to Available: (0,0,1,0) <= Available = (1,0,2,0), satisfied. Pretend to allocate the resource and find a safe sequence. The new state is: Process Allocation Max Available A B C D P0 3 1 4 2 P1 P2 P3 P4

14 Homework 3 Q3 The sequence <P3, P0, P1, P2, P4> is safe
Allocation Max Available A B C D P0 3 1 4 P1 2 P2 P3 P4 Process Need A B C D P0 1 P1 2 P2 3 P3 P4 The sequence <P3, P0, P1, P2, P4> is safe

15 Homework 3 Q3 Second request cannot be granted
Compare request to Need: (0,0,1,0) <= Need_4 = (2,1,1,0), satisfied. Compare request to Available: (0,0,1,0) <= Available = (1,0,1,0), satisfied. However, the new state is not safe. Pretend to allocate the resource and the new state is:

16 Homework 3 Q3 Allocation Max Available A B C D P0 3 1 4 P1 2 P2 P3 P4 Process Need A B C D P0 1 P1 2 P2 3 P3 P4 With (1,0,0,0) left as Available, there is no process that can run immediately.

17 Homework 3 Q4 Now consider a new class of user called Scrubbers. Scrubbers perform an action which is to scrub items in the database. We can have an arbitrary number of scrubbers scrubbing the same item at once. An item should not be read or written while it is being scrubbed. An item should not scrubbed while it is being written or read. Write down a scheme in a format like scheme A above which implements the concurrency functionality of Readers, Writers, and Scrubbers.

18 Homework 3 Q4 Writer Process Shared Data wait(wrt);
var read, wrt, scrub: semaphore (=1); readcount: integer (= 0); scrubcount: integer (= 0); Writer Process wait(wrt); … writing is performed ... signal(wrt);

19 Homework 3 Q4 Reader process Scrubber process wait(read); wait(scrub);
readcount := readcount +1; if readcount = 1 then { wait(wrt); } signal(read); ... reading is performed ... readcount := readcount - 1; if readcount = 0 then { signal(wrt); Scrubber process wait(scrub); scrubcount := scrubcount +1; if scrubcount = 1 then { wait(wrt); } signal(scrub); ... scrubbing is performed ... scrubcount := scrubcount - 1; if scrubcount = 0 then { signal(wrt);

20 Homework 3 Q5 For each statements below, indicate in the box whether it describes static or dynamic linking. Statement SL or DL ? Ability to invoke platform specific code through libraries DL Smaller shipped binary size Less compatibility and dependency issues as whole binary can be shipped. SL Less memory usage

21 Homework 3 Q6 Given five memory partitions of 110 KB, 450 KB, 196KB, 300 KB, and 912 KB (in order), how would each of the first-fit, best-fit, and worst-fit algorithms place processes of 212 KB, 417 KB, 112 KB, and 426 KB (in order)? Which algorithm makes the most efficient use of memory? What is one advantage of first-fit?

22 Homework 3 Q6 Full credit if you used variable sized partitions, so everything fit First-fit: Allocate at the first hole that is big enough. Hole 110KB 450KB 196KB 300KB 912KB Proc KB KB KB 426KB process cannot fit

23 Homework 3 Q6 Best-fit: Allocate at the smallest hole that is big enough Hole 110KB 450KB 196KB 300KB 912KB Proc KB 112KB 212KB 426KB Worst-fit: Allocate at the largest hole Proc KB KB 212KB 426KB process cannot fit

24 Homework 3 Q6 Which algorithm makes the most efficient use of memory?
Best-fit is the best in terms of storage utilization (as the name suggests) since the other two algorithms are unable to fit all four processes. What is one advantage of first-fit? First-fit is faster to execute since it does not have to traverse the whole list.

25 Homework 3 Q7 Consider the following segment table:
What are the physical addresses for the following logical addresses? Segment, offset a. 0, 430 b. 1, 10 c. 2, 500 d. 3, 400 E. 4, 112 Segment Base Length 251 600 1 2332 14 2 122 100 3 1359 580 4 1984 96

26 Homework 3 Q7 What are the physical addresses for the following logical addresses? Answer: a = 681 b = 2342 c. illegal reference, trap to operating system d = 1759 e. illegal reference, trap to operating system Segment Base Length 251 600 1 2332 14 2 122 100 3 1359 580 4 1984 96

27 Virtual Memory Program View

28 Pop Quiz On a piece of paper:
Name ID # Answers to A and B Consider a logical address space of 128 pages of 1024 words each, mapped onto a physical memory of 32 frames. x86-64 bit system with 64 bit words a. How many bits are there in the logical address? b. How many bits are there in the physical address?

29 Finished Questions?


Download ppt "ICS Principles of Operating Systems"

Similar presentations


Ads by Google