Skip to main content

Scheduling exercises

Test yourself with this website

Let's practice the algorithms:

Given those processes:

ProcessArrival timeBurst time (ms)
P114
P203
P335
P428
P531
P627
P745

Exercise 1: Apply Round Robin with q = 3 and write the Gantt chart

đź’ˇAnswer

img_2.png

A solution is to add them by arrival time. P1, then P4, P6, and P3, P5.

Queue time 0 :

ProcessTime left
P23

Queue time 3:

ProcessTime left
P14
P48
P67
P35
P51

Queue time 6:

ProcessTime left
P48
P67
P35
P51
P75
P11

(we've added P7 first, and then P1)
...

Exercise 2: Calculate average wait time for the Round Robin with q = 3

đź’ˇAnswer

P1 : 2 + 13 = 51 wait time
P2: 0
P3: 12 - 3 + 26 - 15 = 18
P4: 4 + 11 + 7 = 32
P5: 12
P6: 7 + 11 + 6 = 24
P7: 12 + 9 = 21

Avg wait time: 16

Exercise 3: write the gantt chart for SJF preemptive

đź’ˇAnswer

img_3.png

On the exam, you can split in multiple boxes from 1 to 1 time unit.
e.g. P2 0 1, P2 1 2, P2 1 3... (to illustrate that you verify for other processes) (but specify you don't do a context switch there)

Exercise 4: Average time for SJF preemptive.

Given this table with processes:

ProcessArrival timeBurst time (ms)Priority
P1043
P2235
P3451
P4282
P5314
P6675

Exercise 5: Do the Gantt chart for SJF preemptive and non-preemptive

Hint: When you are running a process, if another comes with a bigger priority or same one but smaller burst time, context switch. After you end the process, take the smallest job first.

đź’ˇAnswer

img_4.png