0% found this document useful (0 votes)
15 views25 pages

4.process Scheduling

The document discusses process scheduling in operating systems, highlighting the role of the scheduler and various scheduling algorithms used in multi-programmed environments. It covers different scheduling strategies such as First-Come First-Served, Shortest Job First, Round Robin, and Priority Scheduling, along with their performance evaluation criteria. Additionally, it addresses real-time systems scheduling and includes a programming assignment for simulating these scheduling algorithms.

Uploaded by

Zargai
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views25 pages

4.process Scheduling

The document discusses process scheduling in operating systems, highlighting the role of the scheduler and various scheduling algorithms used in multi-programmed environments. It covers different scheduling strategies such as First-Come First-Served, Shortest Job First, Round Robin, and Priority Scheduling, along with their performance evaluation criteria. Additionally, it addresses real-time systems scheduling and includes a programming assignment for simulating these scheduling algorithms.

Uploaded by

Zargai
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 25

Operating Systems

Process Scheduling

Dr. Azhar Mahmood

Email: [email protected]
Scheduling
• When a computer is multi-programmed, it
frequently has multiple processes or threads
competing for the CPU at the same time

• If only one CPU is available, a choice has to be


made which process to run next

• The part of the operating system that makes the


choice is called the scheduler

• Algorithm it uses is called the scheduling algorithm


Scheduling – Process Behavior

Bursts of CPU usage alternate with periods of waiting for I/O.


(a) A CPU-bound process. (b) An I/O-bound process.
When to Schedule
• New process created
• Process exits
• Process blocks on I/O
• I/O interrupt occur
• Clock interrupt
• Non pre-emptive (Stop on I/O, waiting for
other process output)- No Force Control
• Pre-emptive (Time based e.g. 10 sec)-
Force Control
Criteria For Performance Evaluation
UTILIZATION The fraction of time a device is in use. ( ratio of in-use time / total
observation time )

THROUGHPUT The number of job completions in a period of time. (jobs / second )

SERVICE TIME The time required by a device to handle a request. (seconds)

QUEUEING TIME Time on a queue waiting for service from the device. (seconds)

RESIDENCE TIME The time spent by a request at a device.


RESIDENCE TIME = SERVICE TIME + QUEUEING TIME.

RESPONSE TIME Time used by a system to respond to a User Job. ( seconds )

THINK TIME The time spent by the user of an interactive system to figure out the next
request. (seconds)

The goal is to optimize both the average and the amount of variation
5
Categories of Scheduling Algorithms

Different environments different scheduling


algorithms :

•Batch
•Interactive
•Real time
Scheduling Algorithm Goals

Some goals of the scheduling algorithm under different circumstances.


Scheduling in Batch Systems

• First-come First-served (Non Pre-emptive)

• Shortest job first (Non Pre-emptive)

• Shortest remaining Time next (Pre-emptive)


Shortest Job First (SJF)
• If we assume the run times of the jobs are
known in advanced, the non-preemptive batch
SJF algorithm picks the shortest job first.

• Note that this algorithm is optimal when all the


jobs are available simultaneously.

• The difficulty of this algorithm is predicting of


the time usage for a job.
Shortest Job First (SJF)

For example :
(a)FIFO (b)SJF

Turnaround average: Turnaround average:


(8 + 12 + 16+ 20)/4= (4 + 8 + 12 + 20)/4 =
14 in FIFO 11 in SJF

Turnaround is average time from submission to complete a process


Scheduling in Interactive Systems
1. Round-robin scheduling
2. Priority scheduling
3. Multiple queues
4. Shortest process next
5. Guaranteed scheduling
6. Lottery scheduling
7. Fair-share scheduling
Round Robin Scheduling
• Each process is assigned a time interval, called
its quantum.
• If the process is running at the end of quantum ,
the CPU is preempted and given to anther
process.
• If the process has blocked/finished before
quantum has elapsed, CPU switches to the other
process when process blocks.
Round Robin Scheduling

(a) The list of runnable process and


(b) is this list after B uses up its quantum
Round Robin Example
EXAMPLE DATA:
Process Arrival
Service
Time
Time
1 0 8
2 1 4
3
Round Robin, quantum 2
= 4, no priority-based 9
preemption
4 3 5
P1 P2 P3 P4 P1 P3 P4 P3
0 4 8 12 16 20 24 25 26

Avg.Turnaround Time= ( (20-0) + (8-1) + (26-2) + (25-3) )/4 = 74/4 = 18.5

14
Round Robin Scheduling
R.R scheduling is easy and fair the only problem is how to
choose the length of quantum

• If quantum size is too big (e.g. 500 msec) with the


required time for process switching (e.g. 5 msec),
response time suffers. Suppose 10 users hits the Enter
key simultaneously, it means the last process in the list
should wait for a long time.

• If quantum size is too small (e.g. 20 ms) throughputs


suffers. With spending 5 msec on process switching
20% of CPU time will be wasted on administrative
overhead (i.e., saving and loading registers and other
required tasks for process switching).
Priority Scheduling
• Each process is assign a priority and the CPU is
allocated to the process with higher priority
The problem is high-priority processes may run
indefinitely
Solution:
• Decrease the priority of currently running process at
each clock tick. If it drops the priority below the
highest one, executing the highest one
• Assigning the max quantum to each process and then
running the next highest priority process
Priority Scheduling
Priority can be assigned to the processes:
• Statically: external to O.S. e.g. amount of funds, political
factors and ..
• Dynamically: Assign by the system to achieve some
system goals.
• For example I/O bound process should be given CPU
immediately. A simple algorithm for doing that is set
the priority to 1/f, where f is the fraction of the last
quantum that a process used.
• E.g. process that used only 1msec of its 50 msec
quantum would get priority 50, a process that ran 25
msec before blocking would get priority 2, and a process
that used the whole quantum would get priority 1.
Priority Scheduling
• Another way is to group the process into priority
classes and use priority scheduling among the class
but R.R within each class. If the priority class become
empty then the lower class will be run (see the next
slide)

• The problem with this method is if priorities are not


adjusted occasionally, lower priority classes may all
starve to death
Priority Classes

A scheduling algorithm with four priority classes.


Shortest process next
• To minimize the average response time we try to select the
shortest process from the currently runnable processes.
• To find the estimation of running time of a process we use
aging technique as follows:
Estimation of running time = aE(i-1) + (1-a)Ti
Where E(i-1) is the past estimation and Ti is the current run.
Parameter ‘a’ controls the related weight of recent and past
history
For example by selecting a= ½
E0= T0
E1= aE0 + (1-a)T1= T0/2 + T1/2
E2 = aE1 + (1-a)T2 = T0/4 + T1/4 + T2/2
E3= aE2 + (1-a)T3 = T0/8 + T1/8 + T2/4+ T3/2
Guaranteed Scheduling – Usage Ratio Based
• Guaranteed scheduling makes real promises to the
users. For example if there are n users logged in,
each will receives 1/n of CPU power.
• For doing that system should keep track of how
much CPU each process has had since its creation.
• It is straightforward to compute the ratio of actual
CPU time consumed to CPU time entitled. A ratio of
0.5 means that a process has only had half of what it
should have had, and a ratio of 2.0 means that a
process has had twice as much as it was entitled to.
• The algorithm is then to run the process with the
lowest ratio until its ratio has moved above its
closest competitor
Lottery scheduling
• In this algorithm each job receives some number
of lottery tickets, and on each time slice,
randomly a winning tickets will be picked.
• For example if there are 100 tickets and one
process holds 20 of them it will have 20 percents
chance to win each lottery. In long run 20
percent of CPU.
• Lottery scheduling solves the problem of
priority scheduling. Because if the priority of
everyone increases no one gets a service.
Real Time Systems Scheduling
•Hard real-time systems – required to complete a critical
task within a guaranteed amount of time.
•Soft real-time computing – requires that critical
processes receive priority over less fortunate ones.

•Real time algorithms can


Static make their scheduling decisions before the
system starts running. Static scheduling only works
when there is perfect information available in advance
about the work to be done and the deadlines that have
to be met
Dynamic make their scheduling decisions at run time

•Real Time OS will use priority, no pre-emption.


Thread Scheduling

(a) Possible scheduling of user-level threads with a 50-msec process quantum and
threads that run 5 msec per CPU burst.
(b) ) Possible scheduling of kernel-level threads with the same characteristics as (a).
Programming Assignment 2–CPU Scheduling
15 March 2017
Design & Implement a program that simulates the Shortest Job
First (SJF), Round Robin and Priority scheduling:

Assuming that all the jobs will arrive at the same time. Your
program must calculate the
following:
1. Average Waiting Time (AWT)
2. Average Response Time (ART)
3. Average Turnaround Time (ATT)
Waiting Time: Amount of time spent ready to run but not running.
Response Time: Time between submission of requests and first
response to the request.
Turnaround Time: Mean time from submission to completion of
process.

You might also like