Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 30

Presentation:Operatin

g System

Topic:CPU Scheduling and Real Time Scheduling


Group Members:
Muhammad Junaid Tariq
Muhammad Amir
Umme Habiba
Rubeeka Batool
Roll No:
17221598-111
17221598-115
17221598-148
17221598-167
What is CPU scheduling?

 Operating System manages a collection of processes.


 If a system has more processes and one CPU or More processes with fewer CPU’s has
to divide CPU time among different processes
 Selects from among the processes in ready queue, and allocates the CPU to one of them
CPU scheduling decisions may take place when a process:
1. Switches from running to waiting state
2. Switches from running to ready state
3. Switches from waiting to ready
4. Terminates
Scheduling criteria:

 CPU utilization – Keep the CPU as busy as possible


 Throughput – No. of processes that complete their execution per time unit
 Turnaround time – Amount of time to execute a particular process
 Waiting time – Amount of time a process has been waiting in the ready queue
 Response time – Amount of time it takes from when a request was submitted until the
first response is produced, not output.
Scheduling Algorithm Optimization Criteria:

 Max CPU Utilization


 Max Throughput
 Min Turnaround Time
 Min Waiting Time
 Min Response Time
OPERATING SYSTEM SCHEDULING
ALGORITHMS:

 First Come First Serve (FCFS) Scheduling


 Shortest-Job-First (SJF) Scheduling
 Priority Scheduling
 Round Robin(RR) Scheduling
 Multi-level Queue Scheduling
 Multi-level feedback Queue Scheduling
First Come First Serve (FCFS) Scheduling
Shortest Job First (SJF) Scheduling
Non-Pre-emption
Shortest Job First (SJF) Scheduling
Pre-emption
Other Algorithms:

 Priority Algorithm
 Round Robin Algorithm
Priority Scheduling:

 Main Points:
 Here is priority associated with each process.
 At any instance of time, out of all available process, CPU is allocated to the
process which possess the highest priority(Number may be higher or lower).
 Tie is broken using FCFS order.
 No importance to A.T or B.T.
 It supports both Non pre-emptive and pre-emptive versions.
Non Pre-emptive Approach:
 Data and Gantt Chart:
 Highest Priority=Highest Number in Priority Column

P-id A.T B.T Priority C.T TAT W.T


P1 0 4 2 4 4 0
P2 1 3 3 15 14 11
P3 2 1 4 12 10 9
P4 3 5 5 9 6 1
P5 4 2 5 11 7 5

P1 P4 P5 P3 P2
0 4 9 11 12 15
Pre-emptive Approach:
 Data and Gantt Chart:
 Highest Priority=Highest Number in Priority Column

P-id A.T B.T Priority C.T TAT W.T


P1 0 4 2 15 15 11
P2 1 3 3 12 11 8
P3 2 1 4 3 1 0
P4 3 5 5 8 5 0
P5 4 2 5 10 6 4

P1 P2 P3 P4 P5 P2 P1

0 1 2 3 8 10 12 15
Round Robin Algorithm:
 Main Points:
 This algorithm is designed for sharing system, when it is not necessary to complete one process and then
start another, but to be responsive and divide time of the CPU among the process in Ready state.
 Here Ready queue will be treated as circular queue.
 We fix a time quantum up to which a process can hold the CPU in one go, within which either a process
terminates or process must release the CPU and re-enter in the circular queue and wait for the next chance.
 R-Robin is always pre-emptive in nature.
Pre-emptive Approach:
 Data and Gantt Chart:
 Time Quantum=Tq=2
P-id A.T B.T C.T TAT W.T
P0 0 5 13 13 8
P1 1 3 12 11 8
P2 2 1 5 3 2
P3 3 2 9 6 4
P4 4 3 14 10 7

P0 P1 P2 P0 P3 P4 P1 P0 P4
0 2 4 5 7 9 11 12 13 14
Multilevel Queue:

Ready queue is partitioned into separate queues e.g.:


 foreground (interactive)
 background (batch)
Process permanently in a given queue
Each queue has its own scheduling algorithm:
 foreground – RR
 background – FCFS
Multilevel Queue:

 Scheduling must be done between the queues:


 Fixed priority scheduling; (i.e., serve all from foreground then from background).
Possibility of starvation.
 Time slice – each queue gets a certain amount of CPU time which it can schedule
amongst its processes; i.e., 80% to foreground in RR  20% to background in FCFS
Multilevel Feedback Queue:

 A process can move between the various queues; aging can be implemented this way
 Aging :
ageing or aging is a Scheduling technique used to avoid Starvation.

Multilevel feedback-queue scheduler defined by the following parameters:


 number of queues
 scheduling algorithms for each queue
 method used to determine when to upgrade a process
Multilevel Feedback Queue:

 method used to determine when to demote a process


 method used to determine which queue a process will enter when that process needs
service
Example of MLFQ:

 Three queues:

o Q0 – RR with time quantum 8 milliseconds


o Q1 – RR time quantum 16 milliseconds
o Q2 – FCFS
Scheduling:
A new job enters queue Q0 which is served FCFS
When it gains CPU, job receives 8 milliseconds
If it does not finish in 8 milliseconds, job is moved to queue Q1
At Q1 job is again served FCFS and receives 16 additional milliseconds
If it still does not complete, it is preempted and moved to queue Q2
Real time Scheduling
Content :

 Introduction
 Types of real-time system
 Issues in real-time system
 Task categories in real-time systems
 Scheduling algorithms
Real time Systems:

 Real time: It is the time span taken by the system to complete all its tasks and provides
an output for an input. This time span should be the same for computation of all its
tasks.
 Real time system: Real time systems are those which must produce the correct
response within the specified or defined time limit. If it exceeds these time bonds it
results in performance degradation and/or malfunction of system.
 For example in aircraft engine control system, the real time control system should
perform its task within a specified time as the operator/pilot intended and failure of this
can cause the loss of control and possibly the loss of many lives.
Types of Real-time Systems:

 Hard real-time Systems necessarily perform the task within the given specified
deadline. A formal guarantee of always meeting the hard deadline is required .
Examples include air traffic control, vehicle subsystems control and Nuclear power
plant control.
 Soft real-time Systems are the RTOS that perform task almost in the specified
deadline. They do not guarantee a hard deadline. Task can be performed even after the
time has elapsed. Examples of Soft Time Operating Systems include multimedia
transmission and reception, networking, telecom (cellular) networks, web sites and
services and computer games.
Latency:

 a time delay between the cause and the effect of some physical change in the system
being observed
 Two types of latencies affect the performance of real-time systems
1. Interrupt latency : refers to the period of time from the arrival of an interrupt at the
CPU to the start of the routine that services the interrupt
2. Dispatch latency : The time it takes for the dispatcher to stop one process and start
another running is known as the dispatch latency.
Tasks Categories:

Invocation = triggered operations


– Periodic (time-triggered):Periodic tasks have regular arrival times and hard deadlines
– Aperiodic (event-triggered): Aperiodic tasks have irregular arrival times and either soft or
hard deadlines.
Creation
– Static :tasks priorities are fixed before the system runs
– Dynamic: tasks priorities changes as it runs.
Real-Time Scheduling Algorithms:
Static/Offline Scheduling Algorithm:

 Offline scheduling algorithm selects a task to execute with reference to a predetermined


schedule, which repeats itself after specific interval of time.
 For example, if we have three tasks Ta, Tb and Tc then Ta will always execute first,
then Tb and after that Tc respectively.
Dynamic/Online Scheduling Algorithm:

 In Online scheduling a task executes with respect to its priority, which is determined in real
time according to specific rule and priorities of tasks may change during execution . The
online scheduling algorithm has two types. They are more flexible because they can change
the priority of tasks on run time according to the utilization factor of tasks
 Static Priority: In fixed priority if the kth job of a task T1 has higher priority than the kth
job of task T2 according to some specified scheduling event, then every job of T1 will
always execute first then the job of T2 i.e. on next occurrence priority does not change. One
of best example of fixed priority algorithm is rate monotonic scheduling algorithm.
 Dynamic Priority: In dynamic priority algorithm, different jobs of a task may have
different priority on next occurrence, it may be higher or it may be lower than the other
tasks. One example of a dynamic priority algorithm is the earliest deadline first algorithm.

You might also like