Monday, December 20, 2010

Process Scheduling Algorithms


The process Scheduler relies on a process scheduling algorithm, based on a specific policy, to allocate the CPU and move jobs through the system. Early operating system non preemptive policies designed to move batch jobs through the system as efficiency as possible. Most current system, with their emphasis on interactive use and response time, use an algorithm that takes care of the immediate requests of interactive users. CPU scheduling deals with this problem of deciding which of the processes in the ready queue is to be allocated the CPU.


Preemptive scheduling is more useful in high priority process which requires immediate response. For example in Real Time Operating System the consequences of missing one interrupt could be dangerous. 


First Come First Served Scheduling (FCFS)

It is simplest CPU scheduling algorithm. With this scheme, the process that requests the CPU first is allocated the CPU first. The implementation of FCFS policy is easily managed with a FIFO queue. When a process enters in a ready queue, its PCB is linked onto the tail of the queue. When the CPU is free, it is allocated to the process at the head of the queue. The running process is then removed from the queue. The code for the FCFS scheduling is simple to write and understand.

In a strictly FCFS system there are no WAIT queues (each job is run to completion), although there may be systems in which control (context) is switched on a natural wait (I/O request) and then the job resumes on I/O completion.


Process                       Burst Time
P1                                           12
P2                                           6
P3                                           7



P1
P2
P3
       0                                                               12                                    18                                                            25


The waiting time is 0 millisecond for process P1, 12 milliseconds for process P2, and 18 milliseconds for process P3. Thus the average waiting time is (0 + 12 + 18)/3 = 10 milliseconds.


Avg. Waiting Time = 0 + 12 + 18 / 3 = 10 milliseconds