Scheduling Algorithm

Scheduling Algorithm

Every scheduling algorithm has its own criteria to choose next job that will run on CPU.

Timelines

Scheduling is based on information that is available at given time.

Gantt Chart

Gantt charts are used to represent the state of the system and any process in it  and how it changes over time. Gantt chart is a timeline that are used to depict the order of process execution graphically.

First Come First Served Scheduling

FCFS is simplest CPU scheduling algorithm. FCFS scheduling says that the process that enters first should get. It is easy to understand. FCFS method can be managed with FIFO queue.

Example

Banks, Shops queue

Example (1) 

Suppose that there are three processes that arrive in the order shown below. All processes arrive at time 0 but system has decided to serve them in this order.

Process Name 

Arrival Time 

Burst Time 

Process 1 

0 

20 

Process 2 

0 

4 

Process 3 

0 

4 

Process 4 

0 

4 

Gantt Chart

Process 1 

Process 2 

Process 3 

Process 4 

                                                                             0                     20 

                                                               24 

                                                                  28 

                                                          32 

Process 1 is dispatched and runs for 20 units. When process 1 has finished , process 2 is dispatched and runs for 4 time units. Now process 2 starts at time 20. When process 2 has finished at time 24, process 3 is dispatched and runs for 4 time units. Now process 3 starts at time 24 and finished at time 28. Now process 4 runs for 4 time units.  There have been 32 time units used (20+4+4+4) when process 4 has finished.

Waiting Time

Waiting time for a process can be measured by taking its finish time and subtracting burst time and arrival time. 

Waiting Time = Finish time - Burst time - Arrival time

Process Name 

Arrival Time 

Burst Time 

Finish Time 

Waiting Time 

Process 1 

0 

20 

20 

0 

Process 2 

0 

4 

24 

20 

Process 3 

0 

4 

28 

24 

Process 4 

0 

4 

32 

28 

Waiting time for process

Process 1

Waiting time = 20-20-0

Waiting time=0

Process 2

Waiting Time= 24-4-0

Waiting Time=20

process3

Waiting Time=28-4-0

Waiting Time=24

Process4

Waiting Time=32-4-0

Waiting Time=28

Average Waiting Time

Average waiting time for whole set of processes can be calculated by adding all processes waiting times and dividing by the number of processes.

Average Waiting Time = (0+20+24+28)/4

  Average Waiting Time =  72/4

Average Waiting Time = 18

Example(2) 

Process Name 

Arrival Time 

Burst Time 

Process 1 

0 

4 

Process 2 

0 

4 

Process 3 

0 

4 

Process 4 

0 

20 


Gantt Chart


Process 1 

Process 2 

Process 3 

Process 4 

0               4 

               8                                                          

                12                                                     

                     32                            


Process I is dispatched  and runs for 4 time units. When process i has finished , process 2 is dispatched and run for 4 time units. Now process 2 starts at time 4. When process 2 has finished at time 8, process 3 is dispatched and runs for 4 time units. Now process 3 starts at time 8 and finished at time 12. Now process 4 runs for 20 time units. There have been 32 time units use (4+4+4+20) when process 4 has finished.


Process Name 

Arrival Time 

Burst Time 

Finish Time 

Waiting Time 

Process 1 

0 

4 

4 

0 

Process 2 

0 

4 

8 

4 

Process 3 

0 

4 

12 

8 

Process 4 

0 

20 

32 

12 


Waiting time for process

Process 1

Waiting time = 20--0

Waiting time=0

Process 2

Waiting Time= 8-4-0

Waiting Time=4

process3

Waiting Time=12-4-0

Waiting Time=8

Process4

Waiting Time=32-20-0

Waiting Time=12

Average Waiting Time

Average Waiting Time = (0+4+8+12)/4

  Average Waiting Time =  24/4

Average Waiting Time = 6

There is a huge difference between example 1 and example 2. Average waiting time in example 1 is 24 and in example 2 is 6. So FCFS scheduling is not preemptive. FCFS is not good scheduling algorithm.

Shortest Job First Scheduling


Comments

Popular Posts

Computer Abbreviation

Transport Layer

Introduction to Database

Types of database

Threads in operating system

Display devices

Shortcut keys of computer

History of Computer