Sei sulla pagina 1di 10

Paper D-Section-B: Operating System

What is Process Scheduling?


The act of determining which process is in the ready state, and should be moved to the running state
is known as Process Scheduling. Or The act of determining which of the process in ready state should be
selected to be executed by CPU, is known as Process Scheduling. It is also known as CPU Scheduling.
The prime aim of the process scheduling system is to keep the CPU busy all the time.

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.

Computer Science Notes for B.SC Part-II by: M_Fayaz 20


Paper D-Section-B: Operating System
2. Medium term /intermediate level scheduling: Most often, a running process needs I/O operation
which doesn’t requires CPU. Hence during execution of a process when a I/O operation is required
then operating system sends that process from running queue to blocked queue. When a process
completes its I/O operation then it should again shift to ready queue. ALL these decisions are taken
under medium term scheduling.
3. Short term /low level scheduling – When there are lots of processes in main memory initially all
are present in ready queue. Among all of the process a single process is to be selected for execution.
This decision is handled under short term scheduling.

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.

Computer Science Notes for B.SC Part-II by: M_Fayaz 21


Paper D-Section-B: Operating System
Scheduling Criteria:

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.

Below are different time with respect to a process.


Arrival Time: Time at which the process arrives in the ready queue.

Completion Time: Time at which process completes its execution.

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.

Turn Around Time = Completion Time - Arrival Time

Waiting Time (W.T): Time Difference between response time and Arival time.

waiting Time = Response time – Arrival time

Computer Science Notes for B.SC Part-II by: M_Fayaz 22


Paper D-Section-B: Operating System
Scheduling Algorithms:

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.

A CPU scheduling algorithm is considered best if it has the following qualities:

• Maximize CPU utilization


• Maximize throughput
• Minimum turnaround time
• Minimum waiting time
• Minimum response time

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.

Computer Science Notes for B.SC Part-II by: M_Fayaz 23


Paper D-Section-B: Operating System
2. Round Robin Scheduling:
Round Robin (RR) scheduling is a simple, old and most widely used algorithm. RR scheduling is the
preemptive version of FIFO/FCFS scheduling. In the scheduling, processes are scheduled according
to FIFO/FCFS, but each process is assigned a time slice, the process runs till the expiry of time slice.
After that CPU is preempted and the process is sent back to the end of ready list and wait for next
turn.
The performance of this algorithm is totally depending on the size of time slice. The small time slice
can provide good response time.

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.

Computer Science Notes for B.SC Part-II by: M_Fayaz 24


Paper D-Section-B: Operating System
Example: Suppose five processes P1, P2, P3, P4 and P5 and 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 7
P2 2 5
P3 3 1
P4 4 2
P5 6 8
The order in which the above five processes are scheduled using SJF algorithm is shown by using
following Gantt Chart:
P1 P3 P4 P2 P5
1 8 9 11 16 24 Time
At time 1, only P1 is available so it is scheduled and runs for completion. Now time is 8, and P2, P3,
P4 and P5 are available, among these P3 has shortest burst time so P3 is scheduled next and runs for
completion. Then after according to shortest burst time P4, P2 and P5 are scheduled, respectively.
4. Shortest Remaining Time (SRT) Scheduling:
It is preemptive mode of SJF algorithm in which jobs are schedule according to shortest remaining
time. This means when a new process is added to the ready list, it may have the shorter burst time
than the remaining time of currently running process; if so, then currently running process is
preempted and the new arrived shorter burst time process is scheduled.
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 5-1=4-4=0 P1 over
P2 2 3 3-1=2-2=0 P2 over
P3 3 1 1-1=0 P3 over
P4 4 5 5-5=0 P5 over
The order in which the above four processes are scheduled using SRT algorithm is shown by using
following Gantt Chart:
P1 P2 P3 P2 P1 P4
1 2 3 4 6 10 15 Time
[Note: In SRT Scheduling algorithm, once all the processes become available the mode is changed to
non-preemptive.]

Computer Science Notes for B.SC Part-II by: M_Fayaz 25


Paper D-Section-B: Operating System
5. Priority Scheduling:
In many systems processes, run on priority basis and for this purpose priority scheduling is used. In
this scheduling each process is assigned a priority value. The process with the higher priority is
selected for scheduling. Equal priority processes are scheduled on FIFO/FCFS manner.
Priorities are generally indicated by some range of integer values. However, there is no rule whether
the low value represents low priority or higher priority. Some system uses low value for low priority,
other uses low value of higher priority.
Priority scheduling may be preemptive or non-preemptive.
• Non-preemptive priority Scheduling: In non-preemptive priority scheduling, if a process
having highest priority gets the CPU, it runs for completion (the CPU can’t be preempted
from that process till completion).
Example: Suppose four processes P1, P2, P3 and P4 are added to ready list. The arrival time
and estimated rum time (burst time) and priorities for these processes are given below:
(consider higher value represents high priority)
Processes Arrival Time Priority Burst time
P1 1 3 3
P2 2 4 5
P3 3 5 4
P4 4 2 5
The order in which the above four processes are scheduled using non-preemptive priority
algorithm is shown by using following Gantt Chart:
P1 P3 P2 P4
1 4 8 13 18 Time
First of all, P1 is scheduled and runs for completion. Now the current time is 4, at this time
P2, P3 and P4 are available in the ready list. Among these P3 has the highest priority so next
P3 is scheduled. Then after P2 and P4 are scheduled are scheduled in the same sequence
• Preemptive priority Scheduling: In preemptive priority scheduling, the process having
highest priority gets the CPU and starts its execution but meanwhile if the priority of newly
arrived process in the read queue is higher than the priority of the currently running process,
then CPU is preempted from the running process and the newly arrived high priority process
is scheduled.
Example: Suppose four processes P1, P2, P3 and P4 are added to ready list. The arrival time
and estimated rum time (burst time) and priorities for these processes are given below:
(consider higher value represents high priority)

Computer Science Notes for B.SC Part-II by: M_Fayaz 26


Paper D-Section-B: Operating System
Processes Arrival Time Priority Burst time
P1 1 3 3 3-1=2-2=0 P1 over
P2 2 4 5 5-1=4-4=0 P2 over
P3 3 5 4 4-4=0 P3 over
P4 4 2 5 5-5=0 P4 over
The order in which the above four processes are scheduled using preemptive priority
algorithm is shown by using following Gantt Chart:
P1 P2 P3 P2 P1 P4
1 2 3 7 11 13 18 Time

6. Highest Response Ration Next (HRRN) scheduling:


HRRN scheduling is a good technique of scheduling. This scheduling technique selects that process
for scheduling which has the highest “response ratio”.
The response ratio of a process can be calculated by using following formula:
Response ratio (R.r.)= (W+S)/S
Where W=waiting time and S= Service time (burst or run time)
The mode of HRRN scheduling is non-preemptive. The HRRN scheduling not only favours the
shorter processes but also limit the waiting the waiting time of longer processes (this means also
favours the longer processes).
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 (service time)
P1 0 3
P2 2 6
P3 4 4
P4 6 5
P5 8 2

Calculation of Response Ratios:


R.r. = (W+S)/S
As waiting time= response time – arrival time
So W=RT- AT
(RT→ is the current response time, AT→ Arrival time)

Computer Science Notes for B.SC Part-II by: M_Fayaz 27


Paper D-Section-B: Operating System
Waiting time calculation Service
Process Response ratio=R.r.= (W+S)/S
R.T. AT W= RT- AT time =S
P3 9 4 9-4=5 4 (5+4)/4= 2.25 (Highest)
P4 9 6 9-6=3 5 (3+5)/5= 1.6
P5 9 8 9-8=1 2 (1+2)/2=1.5
Next pass: Response time= 13
P4 13 6 13-6=7 5 (7+5)/5=2.4
P5 13 8 13-8=5 2 (5+2)/2= 3.5 (Highest)

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.

Computer Science Notes for B.SC Part-II by: M_Fayaz 28


Paper D-Section-B: Operating System
Thus, in this scheduling, the lower priority queue faces process starvation problem. In process
starvation the waiting time of processes increases too much.
8. Multi-level feedback queue scheduling:
The problem with multi-level queue scheduling is process starvation. So, to overcome this problem
multi-level feedback queue scheduling was introduced. In this scheduling the processes are shifted
among queues. The process that takes more CPU time are shifted to low priority queue. The CPU
first schedule the processes in high priority queue and then move to low priority queue.

[The End]

Prepared by: Muhammad Fayaz

Contact# 0342-5850786

Computer Science Notes for B.SC Part-II by: M_Fayaz 29

Potrebbero piacerti anche