11
Homework Assignment #2 J. H. Wang Oct. 17, 2007

Homework Assignment #2 J. H. Wang Oct. 17, 2007. Homework #2 Chap.5: 5.2, 5.4 Chap.6: 6.3, 6.8* Chap.7: 7.8, 7.10 (Optional: End-of-chapter project for

Embed Size (px)

Citation preview

Page 1: Homework Assignment #2 J. H. Wang Oct. 17, 2007. Homework #2 Chap.5: 5.2, 5.4 Chap.6: 6.3, 6.8* Chap.7: 7.8, 7.10 (Optional: End-of-chapter project for

Homework Assignment #2

J. H. Wang

Oct. 17, 2007

Page 2: Homework Assignment #2 J. H. Wang Oct. 17, 2007. Homework #2 Chap.5: 5.2, 5.4 Chap.6: 6.3, 6.8* Chap.7: 7.8, 7.10 (Optional: End-of-chapter project for

Homework #2

• Chap.5: 5.2, 5.4

• Chap.6: 6.3, 6.8*

• Chap.7: 7.8, 7.10

• (Optional: End-of-chapter project for Chaps. 6)

• Due: two to three weeks (Oct. 31, 2007-Nov. 7, 2007)

Page 3: Homework Assignment #2 J. H. Wang Oct. 17, 2007. Homework #2 Chap.5: 5.2, 5.4 Chap.6: 6.3, 6.8* Chap.7: 7.8, 7.10 (Optional: End-of-chapter project for

• Chap.5– 5.2: Consider the following set of processes, with the length of

the CPU burst given in milliseconds:

The processes are assumed to have arrived in the order P1, P2, P3, P4, P5, all at time 0.(See more on the next page)

Process Burst Time Priority

P1 10 3

P2 1 1

P3 2 3

P4 1 4

P5 5 2

Page 4: Homework Assignment #2 J. H. Wang Oct. 17, 2007. Homework #2 Chap.5: 5.2, 5.4 Chap.6: 6.3, 6.8* Chap.7: 7.8, 7.10 (Optional: End-of-chapter project for

– (a) Draw four Gantt charts that illustrate the execution of these processes using the following scheduling algorithms: FCFS, SJF, nonpreemptive priority (a smaller priority number implies a higher priority), and RR (quantum =1).(b) What is the turnaround time of each process for each of the scheduling algorithms in part (a)?(c) What is the waiting time of each process for each of the scheduling algorithms in part (a)?(d) Which of the algorithms in part (a) results in the minimum average waiting time (over all processes)?

Page 5: Homework Assignment #2 J. H. Wang Oct. 17, 2007. Homework #2 Chap.5: 5.2, 5.4 Chap.6: 6.3, 6.8* Chap.7: 7.8, 7.10 (Optional: End-of-chapter project for

– 5.4: Which of the following scheduling algorithms could result in starvation?(a) First-come, first-served(b) Shortest job first(c) Round robin(d) Priority

Page 6: Homework Assignment #2 J. H. Wang Oct. 17, 2007. Homework #2 Chap.5: 5.2, 5.4 Chap.6: 6.3, 6.8* Chap.7: 7.8, 7.10 (Optional: End-of-chapter project for

• Chap.6– 6.3: Explain why implementing

synchronization primitives by disabling interrupts is not appropriate in a single-processor system if the synchronization primitives are to be used in user-level programs.

Page 7: Homework Assignment #2 J. H. Wang Oct. 17, 2007. Homework #2 Chap.5: 5.2, 5.4 Chap.6: 6.3, 6.8* Chap.7: 7.8, 7.10 (Optional: End-of-chapter project for

– 6.8: The Sleeping-Barber Problem. A barbershop consists of a waiting room with n chairs and a barber room with one barber chair. If there are no customers to be served, the barber goes to sleep. If a customer enters the barbershop and all chairs are occupied, then the customer leaves the shop. If the barber is busy but chairs are available, then the customer sits in one of the free chairs. If the barber is asleep, the customer wakes up the barber. Write a program to coordinate the barber and the customers.

Page 8: Homework Assignment #2 J. H. Wang Oct. 17, 2007. Homework #2 Chap.5: 5.2, 5.4 Chap.6: 6.3, 6.8* Chap.7: 7.8, 7.10 (Optional: End-of-chapter project for

• Chap.7– 7.8: Consider the following snapshot of a system:

AllocationA B C D

MaxA B C D

AvailableA B C D

P0 0 0 1 2 0 0 1 2 1 5 2 0

P1 1 0 0 0 1 7 5 0

P2 1 3 5 4 2 3 5 6

P3 0 6 3 2 0 6 5 2

P4 0 0 1 4 0 6 5 6

Page 9: Homework Assignment #2 J. H. Wang Oct. 17, 2007. Homework #2 Chap.5: 5.2, 5.4 Chap.6: 6.3, 6.8* Chap.7: 7.8, 7.10 (Optional: End-of-chapter project for

Answer the following questions using the banker’s algorithm:

(a) What is the content of the matrix Need?

(b) Is the system in a safe state?

(c) If a request from process P1 arrives for (0,4,2,0),

can the request be granted immediately?

Page 10: Homework Assignment #2 J. H. Wang Oct. 17, 2007. Homework #2 Chap.5: 5.2, 5.4 Chap.6: 6.3, 6.8* Chap.7: 7.8, 7.10 (Optional: End-of-chapter project for

– 7.10: A single-lane bridge connects the two Vermont villages of North Tunbridge and South Tunbridge. Farmers in the two villages use this bridge to deliver their produce to the neighboring town. The bridge can become deadlcoked if both a northbound and a southbound farmer get on the bridge at the same time (Vermont farmers are stubborn and are unable to back up.) Using semaphores, design an algorithm that prevents deadlock. Initially, do not be concerned about starvation (the situation in which northbound farmers prevent southbound farmers from using the bridge, and vice versa).

Page 11: Homework Assignment #2 J. H. Wang Oct. 17, 2007. Homework #2 Chap.5: 5.2, 5.4 Chap.6: 6.3, 6.8* Chap.7: 7.8, 7.10 (Optional: End-of-chapter project for

Optional End-of-Chapter Project

• Project for Chap. 6: Producer-Consumer Problem– Pthreads mutex locks/semaphores– Win32 mutex locks/semaphores