Operating System Chapter 3 Scheduling
Operating System Chapter 3 Scheduling
Operating System Chapter 3 Scheduling
As we know that in multi-programming, more than one processes becomes available in memory to
gain the CPU when available. But only one process can get the CPU at a time. Thus, the need arises to
choose a process among many, to be executed by CPU. This mechanism of process selection, is referred to
as Process Scheduling.
Schedulers are special system software which handle process scheduling in various ways.
Difference between the Scheduler and Dispatcher –
Consider a situation, where various process residing in ready queue and waiting for execution. But CPU can’t
execute all the process of ready queue simultaneously, operating system has to choose a particular
process. So, this procedure of selecting a process among various process is done by scheduler. Now here the
task of scheduler completed. Now dispatcher comes into picture as scheduler have decide a process for
execution, it is dispatcher who takes that process from ready queue to the running status, or you can say that
providing CPU to that process is the task of dispatcher.
Example –
There are 4 process in ready queue, i.e., P1, P2, P3, P4; They all are arrived at t0, t1, t2, t3 respectively. First
in First out scheduling algorithm is used. So, scheduler decided that first of all P1 has come, so this is to be
executed first. Now dispatcher takes P1 to the running state.
t3 t2 t1 t0
Levels of Scheduling:
There are three fundamentals levels of scheduling. They are:
1. Long term/High level scheduling: Due to smaller size of main memory initially all programs are
stored in secondary memory. When they are stored or loaded in main memory they are called
process. So in long term scheduling it is decided that which of the programs from secondary
memory are selected to be loaded in ready queue of main memory.
Types of Scheduling:
There are two main types of scheduling:
1. Non-Preemptive Scheduling: In non-preemptive scheduling once the CPU is allocated to a process,
the process holds (retains) it until the process itself switches from running state to blocked state, or
running state to terminate state. In this scheduling the process that get the CPU will goes for
completion. The CPU can’t be taken away from the process after allocation.
2. Preemptive Scheduling: In preemptive scheduling, the CPU can be taken away from a running
process by O.S., before its completion. In preemptive scheduling the CPU is taken away from a
running process and switched to another process in following cases:
• If a process with a high priority enters in the ready list.
• If a running process completes its time slice.
• If a running process waits for an I/O operation or some event to occur.
Preemptive scheduling was introduced by Microsoft in MS Windows 95 operating system.
There are different scheduling techniques/algorithms but the selection among them can be
made on the basis of following criteria.
1. CPU utilization: Scheduling should be performed in such a way that makes the maximum
utilization of CPU.
2. Balanced Utilization of resources: In executing a process different important resources are
involved such as memory, I/O system, CPU and other resources. So scheduling should be
performed in such a way that makes a balanced utilization of resources.
3. Throughput: Number of processes executed per unit time is called throughput. Scheduling
should be done in such a way that maximize the throughput.
4. Turnaround time: The time interval from submission of process in a system to the time of
its completion is called turnaround time. Scheduling should be done in such a way that
minimize the turnaround time.
5. Waiting time: The total time a process spent in ready queue to get the CPU for execution is
called waiting time. Scheduling should minimize the waiting time of a process.
6. Response Time: The amount of time between the submission of a process and the time when
first response is obtained is called response time. A scheduling should be done in such a way
that minimize the response time of a process.
7. Priorities: Priority denotes how much a process is important. Scheduling should be done in
such a way that processes with high priorities must be given preferences.
Burst Time: Time required by a process for CPU execution also called service
time.
Turn Around Time: Time Difference between completion time and arrival time.
Waiting Time (W.T): Time Difference between response time and Arival time.
The scheduler uses scheduling algorithm to decide which of the following processes in the ready
queue is to be allocated to the CPU. There are several scheduling algorithms, which may be used in different
circumstances by different operating systems.
The most popular and commonly used scheduling algorithms in operating system are being discussed here:
1. FIFO (First In First Out) FCFS (First Come First Serve) Scheduling:
FIFO or FCFS scheduling algorithm is the simplest scheduling algorithm. FIFO / FCFS scheduling
algorithm is a non-preemptive mode of scheduling.
In this scheduling technique, the processes are allocated CPU according to their arrival order. The
process come first in ready list (queue) is the process which gets the CPU first.
Example: Suppose four processes P1, P2, P3 and P4 are added to ready list. The arrival time and
estimated rum time (burst time) for these processes are given below:
Processes Arrival Time Burst time
P1 1 5
P2 2 7
P3 3 2
P4 4 4
The order in which the above four processes are scheduled using FCFS algorithm is shown by using
following Gantt Chart:
P1 P2 P3 P4
1 6 13 15 19 Time
P1 scheduled first. Then after P2, P3 and P4 are scheduled sequentially.
Example: Suppose five processes P1, P2, P3, P4 and P5 are added to ready list. The arrival time and
estimated rum time (burst time) for these processes are given below:
Suppose time slice=2 unit
Processes Arrival Time Burst time
P1 1 4 4-2=2-2=0 P1 over
P2 2 5 5-2=3-2=1-1=0 P2 over
P3 3 1 1-1=0 P3 over
P4 4 6 6-2=4-2=2-2=0 P4 over
P5 6 3 3-2=1-1=0 P5 over
Ready list:
P1 P2 P3 P1 P4 P2 P5 P4 P2 P5 P4
The order in which the above five processes are scheduled using Round Robin algorithm is shown by
using following Gantt Chart:
P1 P2 P3 P1 P4 P2 P5 P4 P2 P5 P4
1 3 5 6 8 10 12 14 16 17 18 20 Time
3. Shortest Job First (SJF)/Shortest Job Next (SJN) Scheduling:
SJF/SJN is a non-preemptive scheduling algorithm. SJF Scheduling associates/compare the estimate
run time (burst time) of processes with each other and selects that process for scheduling which has
the shortest burst time. So, in this scheduling technique the shortest job gets the CPU first.
The order in which the above five processes are scheduled using HRRN algorithm is shown by using
following Gantt Chart:
P1 P2 P3 P5 P4
0 3 9 13 15 20 Time
First P1 is scheduled and runs for completion, as at time 0 it is the only available process. Now time
is 3 , but this time only P2 is available so we scheduled P2, which runs for completion. Now time is
13, at this time P3, P4 and P5 are available, but the Response ratio of P3 is highest so P3 is scheduled
next and runs for completion. Then we again calculate the response ratio of P4 and P5. P5 has the
high response ratio so P5 will be scheduled and complete its execution. Finally, P4 is scheduled.
7. Multi-level Queue Scheduling:
The scheduling technique in which processes are classified into different groups and each group is
placed into a separate queue, is called multi-level queue scheduling. In this scheduling, actually the
ready queue is divided into several sub-queues. Each may have its own scheduling algorithm.
Typically, processes are divided into system, interactive, batch and normal processes. The system
processes (processes that belong to O.S) always have the highest priority. Then after the interactive
processes have higher priority. Batch and normal processes have lowest priority. The processes in
batch and normal queue are scheduled only if there was no system and interactive processes left in
their respective queues.
[The End]
Contact# 0342-5850786