Sei sulla pagina 1di 3

Process Scheduling Algorithms

Given the scenario in the table, we will determine the behavior of the different
scheduling algorithms.

Note the following:


1. In this case, higher priority is implied by a higher value. Some operating
systems may do it the other way around. In that case, higher priority is
implied by a lower value.
2. Same type of scheduling algorithms may lead to different behavior depending
on the policy for inserting a new job in the READY queue. For example, the
new job may be inserted before or after the existing jobs with the same
priority.
3. For the Shortest Job First (SJF) algorithm, the algorithm compares the
remaining service time of the running job with the service times of the jobs
in the READY queue. For example, consider the following scenario J1 is the
running job with service time 5 and another job J2 with service time 4
arrives when J1 finishes its first quantum. At this point J1 has 4 units of
service time remaining. SJF will continue running J1.
4. Performance of scheduling algorithms is determined by the following metrics:

Turnaround Time: Completion Time – Arrival Time


Waiting Time: Turnaround Time – Service Time
Response Time: The first time the job got scheduled – Arrival Time
Throughput: The average number of jobs completed per unit time within a
given time interval

Scenario:

Job ID 1 2 3 4 5
Arrival time 0 1 2 3 4
Service time 10 1 2 1 5
Priority 7 10 5 5 9

a) Gantt charts to show behavior of scheduling algorithms

FCFS: _________________________________________
| 1 |2 | 3 |4 | 5 |
|___________________|__|____|__|_________|
0 10 11 13 14 19

RR: ________________________________________________
| 1|2 |3 |4 |5 |1 |3 |5 |1 |5 |1 |5 |1 |5 | 1 |
|__|__|__|__|__|__|__|__|__|__|__|__|__|__|_____|
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 19

SJF: _________________________________________
(non-pre) | 1 |2 |4 | 3 | 5 |
|___________________|__|__|____|_________|
0 10 11 12 14 19
SJF(pre-emp):
________________________________________
|1 |2 | 3 |4 | 5 | 1 |
|__|__|___|__|_________|________________|
0 1 2 4 5 10 19

Non-preemptive priority scheduling:

_________________________________________
| 1 |2 | 5 | 3 |4 |
|___________________|__|__________|____|__|
0 10 11 16 18 19

Preemptive priority scheduling:


_________________________________________
|1 |2 |1 | 5 | 1 | 3 |4 |
|__|__|___|_________|_____________|___|__|
0 1 2 4 9 16 18 19

b) Turnaround Time

FCFS: 10,10,11,11,15
RR : 19,1,5,1,10
NPSJF: 10,10,12,9,15
PSJF: 19,1,2,2,6
NPPS: 10,10,16,16,12
PPS : 16,1,16,16,5

c) Wait Time

FCFS : 0,9,9,10,10
RR : 9,0,3,0,5
NPSJF : 0,9,10,8,10
PSJF : 9,0,0,1,1
NPPS : 0,9,14,15,7
PPS : 6,0,14,15,0

Think about the following issues:

1. The pros and cons of the following:


• Preemptive vs. run to completion nonpreemtive scheduling
• Large vs. small time quantum for RR scheduling

2. Present a scenario where it makes sense to change the priority dynamically.


Describe a simple policy to change the priority.

3. Suppose not all the processes are always in the main memory and the ready
processes may be swapped in and out of the memory. Think of a 2-level
scheduling algorithm where the processes in level-1 are in memory and the
processes in Level-2 are in secondary storage.

4. Which is the optimal algorithm for the minimal average turnaround time? Why?
5. Consider five jobs, A through E, with run times of 2, 4, 1, 1, and 1
respectively. Their arrival times are 0, 0, 3,3, and 3. Is the SJF the
optimal algorithm?

6. How would you design a scheduling algorithm to guarantee that each user will
get 1/n-th time assuming there are n users in the system.

Potrebbero piacerti anche