Saturday, 14 June 2014

OS - Scheduling algorithms

Post By: Hanan Mannan
Contact Number: Pak (+92)-321-59-95-634
-------------------------------------------------------

OS - Scheduling algorithms

We'll discuss four major scheduling algorithms here which are following
  • First Come First Serve (FCFS) Scheduling
  • Shortest-Job-First (SJF) Scheduling
  • Priority Scheduling
  • Round Robin(RR) Scheduling
  • Multilevel Queue Scheduling

First Come First Serve (FCFS)

  • Jobs are executed on first come, first serve basis.
  • Easy to understand and implement.
  • Poor in performance as average wait time is high.
First Come First Serve Scheduling Algorithm
Wait time of each process is following
ProcessWait Time : Service Time - Arrival Time
P00 - 0 = 0
P15 - 1 = 4
P28 - 2 = 6
P316 - 3 = 13
Average Wait Time: (0+4+6+13) / 4 = 5.55

Shortest Job First (SJF)

  • Best approach to minimize waiting time.
  • Impossible to implement
  • Processer should know in advance how much time process will take.
Shortest Job First Scheduling Algorithm
Wait time of each process is following
ProcessWait Time : Service Time - Arrival Time
P03 - 0 = 3
P10 - 0 = 0
P216 - 2 = 14
P38 - 3 = 5
Average Wait Time: (3+0+14+5) / 4 = 5.50

Priority Based Scheduling

  • Each process is assigned a priority. Process with highest priority is to be executed first and so on.
  • Processes with same priority are executed on first come first serve basis.
  • Priority can be decided based on memory requirements, time requirements or any other resource requirement.
Priority Scheduling Algorithm
Wait time of each process is following
ProcessWait Time : Service Time - Arrival Time
P00 - 0 = 0
P13 - 1 = 2
P28 - 2 = 6
P316 - 3 = 13
Average Wait Time: (0+2+6+13) / 4 = 5.25

Round Robin Scheduling

  • Each process is provided a fix time to execute called quantum.
  • Once a process is executed for given time period. Process is preempted and other process executes for given time period.
  • Context switching is used to save states of preempted processes.
Round Robin Scheduling Algorithm
Wait time of each process is following
ProcessWait Time : Service Time - Arrival Time
P0(0-0) + (12-3) = 9
P1(3-1) = 2
P2(6-2) + (14-9) + (20-17) = 12
P3(9-3) + (17-12) = 11
Average Wait Time: (9+2+12+11) / 4 = 8.5

Multi Queue Scheduling

  • Multiple queues are maintained for processes.
  • Each queue can have its own scheduling algorithms.
  • Priorities are assigned to each queue.
Multi Queue Scheduling Algorithm

0 comments: