Homework 2 ECE 4310 Fall 2018 Gabriel Kuri

4 Problems - 50 pts total

1 (5 pts) Explain in detail the difference between preemptive and non-preemptive scheduling.

2 (15 pts) Consider the following processes arriving at the ready queue and dispatched to a single core CPU:

PID Arrival Time Burst (ms) Priority 10 0 5 2 11 1 7 1 12 3 2 9 13 8 15 4 14 17 4 11 15 20 12 6

Using the following scheduling :

First-come first-served (FCFS) Preemptive shortest job first (PSJF) Preemptive Round-robin with 4 ms quantum Priority with a priority aging of +1 every 5 ms

Answer the following:

(a) Draw a Gantt chart showing the arrival time and run times for each . (b) Calculate the wait time for each process and average waiting time. (c) Calculate the turnaround time for each process.

3 (15 pts) The sleeping barber problem is a classic process problem, where a barber shop has one barber, one barber chair, and n chairs for waiting customers, if any, to sit and wait. If there are no customers present, the barber sits down in the barber chair and sleeps. When a customer arrives, he has to wake up the sleeping barber. If additional customers arrive while the barber is cutting a customer’s hair, they either sit down (if there are empty chairs) or leave the shop (if all chairs are full). Consider a slight modification to the classic problem, where there are m barbers and n chairs at the barber shop, instead of just one. Write a program in C or pseudocode using semaphores to implement this problem (with m barbers and n barber chairs).

1 4 (15 pts) Recall the various detection and prevention algorithms we’ve discussed in class and consider the following snapshot of a system with five processes (P10, P11, P12, P13, P14) and four resources (R1, R2, R3, R4). R1, R2, R3, and R4 have a total of 5, 7, 10, and 11 resources, respectively. There are no current outstanding queued unsatisfied requests.

Table 1: Allocation Table 2: Max Need

PID R1 R2 R3 R4 PID R1 R2 R3 R4 10 0 0 1 2 10 0 0 3 2 11 1 0 0 0 11 2 7 5 0 12 1 0 1 4 12 5 6 5 6 13 0 3 5 1 13 4 3 5 6 14 2 3 3 2 14 0 6 5 2

Is the system currently in a safe or unsafe state? If safe, provide the process execution order.

2