OS course assignment 5 Question 1&2

Q1

Consider the following set of processes, with the length of the CPU-burst time given in milliseconds:

Process Burst Time Priority
P1 10 3
P2 1 1
P3 2 3
P4 1 4
P5 5 2

The processes are assumed to have arrived in the order P1, P2, P3, P4, P5, all at time 0.
a. Draw four Gantt charts illustrating the execution of these processes . using FCFS, SJF, a nonpreemptive priority (a smaller priority number implies a higher priority), and RR (quantum = 1) scheduling.
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 schedules in part a results in the minimal average waiting time (over all processes)?


a.

b.

Turnaround time:
FCFS: 10, 11, 13, 14, 19
SJF: 19, 1, 4, 2, 9
nonpreemptive priority: 16, 1, 18, 19, 6
RR: 19, 2, 7, 4, 14

c.

Waiting time:
FCFS: 0, 10, 11, 13, 14
SJF: 9, 0, 2, 1, 4
nonpreemptive priority: 6, 0, 16, 18, 1
RR: 9, 1, 5, 3, 9

d.

Average waiting time:
FCFS: 9.6
SJF: 3.2
nonpreemptive priority: 8.2
RR: 5.4

SJF has minimal average waiting time.

Q2

Assume three processes P1, P2, and P3:
P1 consists of one thread T11
P2 consists of three threads T21, T22, and T23
P3 consists of two threads T31 and T32.
The following are the CPU bursts for these processes and their threads:

process thread cpu burst
P1 T11 7
P2 T21 4
T22 2
T23 4
P3 T31 6
T32 3

Assume that all threads arrive at the same time 0.
Show in gantt charts the execution of these processes using Round-Robin scheduler and Tq=5 time units:
(1) If the threads are user-level threads
(2) If the threads are kernel (OS) supported threads.
Calculate the waiting times (Tw) and turnaround times (Ttr) for each process and their average values for both cases (1) and (2).


Gantt charts:

Waiting time:

(1):
P1: 15 - 5 = 10
P2: 5 + 17 - 10 = 12
P3: 10 + 22 - 15 = 17
average: 13
(2):
P1: 23 - 5 = 18
P2: 5
P3: 15 + 25 - 23 = 17
average: 13.3

Turnaround time:

(1):
P1: 17
P2: 22
P3: 26
average: 65 / 3 = 21.7
(2):
P1: 25
P2: 15
P3: 25
average: 65 / 3 = 21.7