0% found this document useful (0 votes)
19 views217 pages

Lec+2 +OS+Part+1

Uploaded by

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

Lec+2 +OS+Part+1

Uploaded by

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

Big Data -Part -1

Operating
Systems
Operating
system OS Road Map
Concepts
+
Process
+ synchronization
+
Processes&
Threads

+
CPU
Scheduling

+
Memory
©Ahmed Operating Management
2
Hagag Systems
Reference
Computer Operating System Concepts
• Author: Silberschatz
• Publisher: Wiley
• Edition: Sixth
• ISBN: 0471250600
Operating System
What Operating Systems Do?
• OS is a resource allocator
 Manages all resources.
 Decides between conflicting requests for effici
ent and fair resource use.

• OS is a control program
 Controls execution of programs to prevent
errors and improper use of the computer.

©Ahmed Operating 4
Hagag Systems
Single processor
• Memory Layout for a Simple Batch System
Single processor
• Multi-programmed Batch Systems
• Several jobs are kept in main memory at the same time, and the CPU is
multiplexed among them
• OS features needed
• I/O routine supplied by the system
• Memory management
• The system must allocate the memory
to several jobs
• CPU scheduling
• The system must choose among
several jobs ready to run
Parallel Systems
• Systems with more than one CPU in close communication
• Also known as multiprocessor systems
• Tightly coupled system
• processors share memory and a clock;
• communication usually takes place through the shared memory
• Advantages of parallel system:
• Increased throughput
• Economical
• Increased reliability
• graceful degradation
Distributed Systems
• Distribute the computation among several physical processors
• Loosely coupled system
• Each processor has its own local memory
• processors communicate with one another through various
communications lines, such as high-speed buses or telephone lines
• Advantages of distributed systems
• Resources Sharing
• Computation speed up
• Reliability
Difference between clustered system and
distributed system
• Distributed System:
A distributed system refers to a collection of independent
computers or nodes that work together as a single cohesive
system. These nodes are connected through a network and
communicate with each other to achieve a common goal.
• In a distributed system, the nodes are geographically dispersed
and can be heterogeneous, meaning they may have different
hardware configurations, operating systems, or software
components
Difference between clustered system and
distributed system
1. Distributed System:
Decentralization: There is no central control or single point of failure in a
distributed system. Each node operates independently and makes its
own decisions.
2. Autonomy: Each node in a distributed system has its own local memory
and processing capabilities, allowing it to perform tasks independently.
3. Transparency: The system appears as a single, integrated entity to
users and applications, hiding the complexity of the underlying network
and node interactions.
4. Scalability: Distributed systems can scale horizontally by adding more
nodes to the network, increasing processing power and storage capacity.
5. Fault tolerance: Distributed systems are designed to handle failures or
crashes of individual nodes without disrupting the overall system.
Examples of distributed systems include peer-to-peer networks,
distributed file systems, and distributed databases.
Distributed Systems Cont’d
• Requires networking infrastructure
• Local area networks (LAN) or Wide area networks (WAN)
• May be either client-server or peer-to-peer systems
Clustered Systems
• Clustered System:
A clustered system is a type of parallel computing architecture
in which multiple computers or servers, known as nodes, are
tightly interconnected and work together to perform a specific
task or provide a service.
• In a cluster, the nodes are typically located in close proximity
and are homogeneous, meaning they have similar hardware
configurations and software setups.
Clustered Systems
• Clustering allows two or more systems to

share storage

• Provides high reliability

• Asymmetric clustering: one server runs the

application or applications while other


servers standby

• Symmetric clustering: all N hosts are

running the application or applications


Difference between clustered system and
distributed system
Clustered System
1. Centralization: Clusters have a central controlling entity, often referred
to as the cluster manager or master node, which coordinates and
manages the resources and tasks across the nodes.
2. High performance: Clusters are designed to achieve high performance
and improved processing power by dividing the workload among the
nodes and executing tasks in parallel.
3. Load balancing: The cluster manager distributes the workload evenly
across the nodes, ensuring that each node is utilized efficiently.
4. High availability: Clustering provides fault tolerance by allowing
redundant nodes to take over if a node fails, ensuring continuous
operation of the system.
• Examples of clustered systems include high-performance computing
clusters, web server clusters, and database clusters.
Operating system
Processes

©Ahmed Operating 15
Hagag Systems
Operating System
What Operating Systems Do?
• OS is a resource allocator
 Manages all resources.
 Decides between conflicting requests for effici
ent and fair resource use.

• OS is a control program
 Controls execution of programs to prevent
errors and improper use of the computer.

©Ahmed Operating 16
Hagag Systems
Process Concept

Program vs. Process


• A program is a passive entity such as the f ile that contains the
list of instructions stored on a disk always referred to as an
executable file.
• A program becomes a process when an executable file is loaded
into the memory and then becomes an active entity.

©Ahmed Operating 17
Hagag Systems
Process Concept
• The fundamental task of any operating system i
s the
process management.
• Processes include not only a text but also include a set of resources
such as open f il es and pending signals. Processes also contain
internal kernel data, processor state, an address space, and a data
section.

©Ahmed Operating 18
Hagag Systems
Process Concept
• OS must allocate resources to processes, enable sharing of
information, protect resources, and enable the synchronization
among processes.

©Ahmed Operating 19
Hagag Systems
Process Elements

• Segments of a process represents the follow


ing
• components:
 Text Section: the program code. This is typically read-only, and might be shared
by a number of processes.
 Data Section: containing global variables.
 Heap: containing memory dynamically allocated during run time.
 Stack: containing temporary data.
• Function parameters, return addresses, local variables.

©Ahmed Operating 20
Hagag Systems
Process Concept
• Process in
Memory

©Ahmed Operating 21
Hagag Systems
Process Control Block (PCB)

• For better control of processe


s, operating systems need t o
consider their dynamic behaviors.
• Each process is represented in the OS
by a Process Control Block (PCB).

©Ahmed Operating 22
Hagag Systems
Process Control Block (PCB)
• Process Control Block (PCB) (1/3)
 Process identification information
 Process identifier: numeric identifiers
represent the unique process identifier
 User identifier: the user who is responsible for the job).
 Identif ier of the parent process that created this
process.

©Ahmed Operating 23
Hagag Systems
Process Control Block (PCB)

• Process Control Block (PCB) (2/3)


 Processor state Information
 Process state – running, waiting, etc
 Program counter
 location of instruction to next execute
 CPU registers
 contents of all process-centric registers

©Ahmed Operating 24
Hagag Systems
Process Control Block (PCB)
• Process Control Block (PCB) (3/3)
 CPU scheduling information
 priorities, scheduling queue pointers
 Memory-management information
 memory allocated to the process
 Accounting information
 CPU used, clock time elapsed since start, time
limits
 I/O status information
 I/O devices allocated to process, list of open
©Ahmed Operating 25
Hagag f iles Systems
Process State

• As a process executes, it changes state


 new: The process is being created
 running: Instructions are being executed
 waiting: The process is waiting for some event to
occur
 ready: The process is waiting to be assigned to a
processor
 terminated: The process has finished execution

©Ahmed Operating 26
Hagag Systems
Process State
• Diagram of Process
State

©Ahmed Operating 27
Hagag Systems
Process State

©Ahmed Operating 28
Hagag Systems
Process State

©Ahmed Operating 29
Hagag Systems
Process State

©Ahmed Operating 30
Hagag Systems
Process State

©Ahmed Operating 31
Hagag Systems
Process State

©Ahmed Operating 32
Hagag Systems
Process State

©Ahmed Operating 33
Hagag Systems
CPU Switch From Process to
Process

©Ahmed Operating 34
Hagag Systems
Process Scheduling
• Job queue – set of all processes in the system
• Ready queue – set of all processes
residing in main memory, ready and waiting
to execute
• Device queues – set of processes waiting for an I/O device
• Processes migrate among the various queues

©Ahmed Operating 35
Hagag Systems
Process Scheduling
• Short-term scheduler (or CPU scheduler)
 Selects which process should be executed next and allocates CPU.
 Invoked frequently (milliseconds) →(must be fast).
• Long-term scheduler (or job scheduler)
 Selects which processes should be brought into the
ready queue.
 Invoked infrequently (seconds, minutes) →(may be slow).
 Controls the degree of multiprogramming.

©Ahmed Operating 36
Hagag Systems
Process Scheduling
Medium-term scheduler
 Can be added if degree of multiple programmi
ng needs to decrease
 Remove process from memory, store on disk, bring back in
from disk to continue execution: swapping

©Ahmed Operating 37
Hagag Systems
Operating systems
Threads

©Ahmed Operating 38
Hagag Systems
Introduction

• A thread is a basic unit of CPU utilization; it comprises a thread ID, a

program counter, a register set, and a stack.

• It shares with other threads belonging to the same process its code

section, data section, and other operating-system resources, such as

open files and signals.

©Ahmed Operating 39
Hagag Systems
CONT’S Introduction

• Let's say, for example, a program is not capable of drawing pictures

while reading keystrokes.

• The program must give its full attention to the keyboard input

lacking the ability to handle more than one event at a time.

• The ideal solution to this problem is the seamless execution of two

or more sections ofOperating


©Ahmed
a program at the same time. Threads allows us
40
Hagag Systems
Introduction

©Ahmed Operating 41
Hagag Systems
Operating
Systems
CPU Scheduling
Operating system
CPU Scheduling

©Ahmed Operating 43
Hagag Systems
Basic Concepts
• CPU scheduling is the central in multi-
programming system.
• Maximum CPU utilization obtained with
multiprogramming (prevent CPU from being idle).
• Processes residing in the main memory is selected by the
Scheduler that is:
 Concerned with deciding a policy about which process is to
be selected.
 Process selection based on a scheduling algorithm.

©Ahmed Operating 44
Hagag Systems
Basic Concepts

©Ahmed Operating 45
Hagag Systems
Basic Concepts

©Ahmed Operating 46
Hagag Systems
Basic Concepts
• Process execution consists of a
cycle of CPU execution and I/O wait.
• Processes alternate between these
t w o st at es. Proc ess exec ut ion
begins with a CPU burst. That is
followed by an I/O burst, which is
followed by another CPU burst, then
another I/O burst, and so on.
• CPU burst s vary greatly from
p roc ess to p roc ess and from
computer to computer.

©Ahmed Operating 47
Hagag Systems
Basic Concepts

Schedulers
• Long-term scheduler chooses some of them to go to
memory (ready queue).
• Then, short-term scheduler (or CPU scheduler) chooses
from ready queue a job to run on CPU.
• Medium-term scheduler may move (swap) some partially-
e x e c u t e d j o b s f ro m m e m o r y t o d i s k ( t o e n h a n c e
performance).

©Ahmed Operating 48
Hagag Systems
Basic Concepts

CPU Scheduler
• Whenever the CPU becomes idle, the operating system must
select one of the processes in the ready queue to be executed.
The selection process is carried out by the short-term scheduler,
or CPU scheduler.

©Ahmed Operating 49
Hagag Systems
Basic Concepts

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

©Ahmed Operating 50
Hagag Systems
Basic Concepts
Scheduling can be
• Non-preemptive
 Once a process is allocated the CPU, it
does not leave until terminate.
• Preemptive
 OS can force (preempt) a process from CPU
at anytime.
 Say, to allocate CPU to another higher-priority process.

©Ahmed Operating 51
Hagag Systems
Basic Concepts

Non-preemptive and Preemptive


Which is harder to implement? and
why?

©Ahmed Operating 52
Hagag Systems
Basic Concepts

Non-preemptive and Preemptive


• Preemptive is harder: Need to maintain consistency of data shared
between processes, and more importantly, kernel data structures
(e.g., I/O queues).

©Ahmed Operating 53
Hagag Systems
Basic Concepts
Dispatcher
• Dispatcher module gives control of the CPU to the process
selected by the short-term scheduler; this involves:
 Switching context.
 Switching to user mode.
 Jumping to the proper location in the user program to restart
that program.
• Dispatch latency – time it takes for the dispatcher to stop
one process and start another running.

©Ahmed Operating 54
Hagag Systems
Basic Concepts
Dispatcher

©Ahmed Operating 55
Hagag Systems
Basic Concepts
Dispatch
er

©Ahmed Operating 56
Hagag Systems
Basic Concepts
Dispatch
er

©Ahmed Operating 57
Hagag Systems
Basic Concepts
Dispatch
er

©Ahmed Operating 58
Hagag Systems
Basic Concepts
• CPU utilization – keep the CPU as busy as possible.
• Throughput – #of processes that complete their execution per time unit.
• Turnaround time – amount of time to execute a particular process. (time from
submission to termination)
• 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 f irst response is produced, not output.

©Ahmed Operating 59
Hagag Systems
Scheduling Criteria
Scheduling Algorithm Optimization
Criteria

• Max CPU utilization.


• Max throughput.
• Min turnaround time.
• Min waiting time.
• Min response time.

©Ahmed Operating 60
Hagag Systems
Scheduling Algorithms
• There are many different CPU-scheduling algorithms:
1. First Come, First Served (FCFS).
2. Shortest Job First (SJF).
 Preemptive SJF.
 Non-Preemptive SJF.
3. Priority.
4. Round Robin.
5. Multilevel queues.

©Ahmed Operating 61
Hagag Systems
Scheduling Algorithms
1. First-Come, First-Served (FCFS) Scheduling
Process Burst
Time
P1 24
P2 3
P3 3
Suppose that the processes arrive in the order: P1 , P2 , P3
The Gantt Chart for the schedule is:

Note: A process may have many CPU bursts, but in the


following examples we show only one for simplicity.

©Ahmed Operating 62
Hagag Systems
Scheduling Algorithms
1. First-Come, First-Served (FCFS) Scheduling
Process Burst
Time
P1 24
P2 3
P3 3
Suppose that the processes arrive in the order: P1 ,
P2 , P3
The Gantt Chart for the schedule is:

P1
0

©Ahmed Operating 63
Hagag Systems
Scheduling Algorithms
1. First-Come, First-Served (FCFS) Scheduling
Process Burst
Time
P1 24
P2 3
P3 3
Suppose that the processes arrive in the order: P1 ,
P2 , P3
The Gantt Chart for the schedule is:

P1
0

©Ahmed Operating 64
Hagag Systems
Scheduling Algorithms
1. First-Come, First-Served (FCFS) Scheduling
Process Burst
Time
P1 24
P2 3
P3 3
Suppose that the processes arrive in the order: P1 ,
P2 , P3
The Gantt Chart for the schedule is:

P1
0

©Ahmed Operating 65
Hagag Systems
Scheduling Algorithms
1. First-Come, First-Served (FCFS) Scheduling
Process Burst
Time
P1 24
P2 3
P3 3
Suppose that the processes arrive in the order: P1 ,
P2 , P3
The Gantt Chart for the schedule is:

P1
0
Waiting Time
��� ��� ����
� �

©Ahmed Operating 66
Hagag Systems
Scheduling Algorithms
1. First-Come, First-Served (FCFS) Scheduling
Process Burst
Time
P1 24
P2 3
P3 3
Suppose that the processes arrive in the order: P1 ,
P2 , P3
The Gantt Chart for the schedule is:

P1
0
Waiting Time
���� ��� ����

0 24 27
Average waiting time: (0 + 24 + 27)/3 =
17
©Ahmed Operating 67
Hagag Systems
Scheduling Algorithms
1. First-Come, First-Served (FCFS) Scheduling
Process Burst
Time
P1 24
P2 3
P3 3
Suppose that the processes arrive in the order: P1 ,
P2 , P3
The Gantt Chart for the schedule is:

P1
0
Turnaround Time
��� ��� ����
� �

©Ahmed Operating 68
Hagag Systems
Scheduling Algorithms
1. First-Come, First-Served (FCFS) Scheduling
Process Burst
Time
P1 24
P2 3
P3 3
Suppose that the processes arrive in the order: P1 ,
P2 , P3
The Gantt Chart for the schedule is:

P1
0
Turnaround Time
��� ��� ����
� �
24 27 30
Average turnaround time: (24 + 27 + 30)/3 =
27
©Ahmed Operating 69
Hagag Systems
Scheduling Algorithms
1. First-Come, First-Served (FCFS) Scheduling
Process Burst
Time
P1 24
P2 3
P3 3
Suppose that the processes arrive in the order: P1 ,
P2 , P3
The Gantt Chart for the schedule is:

P1
0
Response Time
��� ��� ����
� �

©Ahmed Operating 70
Hagag Systems
Scheduling Algorithms
1. First-Come, First-Served (FCFS) Scheduling
Process Burst
Time
P1 24
P2 3
P3 3
Suppose that the processes arrive in the order: P1 ,
P2 , P3
The Gantt Chart for the schedule is:

P1
0
Response Time
���� ��� ����

0 24 27
Average response time: (0 + 24 + 27)/3 =
17
©Ahmed Operating 71
Hagag Systems
Scheduling Algorithms
1. First-Come, First-Served (FCFS) Scheduling
Process Burst
Time
P1 24
P2 3
P3 3
Suppose that the processes arrive in the order: P2 ,
P3 , P1
The Gantt Chart for the schedule is:

©Ahmed Operating 72
Hagag Systems
Scheduling Algorithms
1. First-Come, First-Served (FCFS) Scheduling
Process Burst
Time
P1 24
P2 3
P3 3
Suppose that the processes arrive in the order: P2 ,
P3 , P1
The Gantt Chart for the schedule is:
P2 P3 P
0

©Ahmed Operating 73
Hagag Systems
Scheduling Algorithms
1. First-Come, First-Served (FCFS) Scheduling
Process Burst
Time
P1 24
P2 3
P3 3
Suppose that the processes arrive in the order: P2 ,
P3 , P1
The Gantt Chart for the schedule is:
P2 P3 P
0

©Ahmed Operating 74
Hagag Systems
Scheduling Algorithms
1. First-Come, First-Served (FCFS) Scheduling
Process Burst
Time
P1 24
P2 3
P3 3
Suppose that the processes arrive in the order: P2 ,
P3 , P1
The Gantt Chart for the schedule is:
P2 P3 P
0

©Ahmed Operating 75
Hagag Systems
Scheduling Algorithms
1. First-Come, First-Served (FCFS) Scheduling
Process Burst
Time
P1 24
P2 3
P3 3
Suppose that the processes arrive in the order: P2 ,
P3 , P1
The Gantt Chart for the schedule is:
P2 P3 P
0

Waiting Time
��� ��� ����
� �

©Ahmed Operating 76
Hagag Systems
Scheduling Algorithms
1. First-Come, First-Served (FCFS) Scheduling
Process Burst
Time
P1 24
P2 3
P3 3
Suppose that the processes arrive in the order: P2 ,
P3 , P1
The Gantt Chart for the schedule is:
P2 P3 P
0

Waiting Time
���� ���� ����
6 0 3

Average waiting time: (6 + 0 + 3)/3 =


3
©Ahmed Operating 77
Hagag Systems
Scheduling Algorithms
1. First-Come, First-Served (FCFS) Scheduling
Process Burst
Time
P1 24
P2 3
P3 3
Suppose that the processes arrive in the order: P2 ,
P3 , P1
The Gantt Chart for the schedule is:
P2 P3 P
0

Turnaround Time
��� ��� ����
� �

©Ahmed Operating 78
Hagag Systems
Scheduling Algorithms
1. First-Come, First-Served (FCFS) Scheduling
Process Burst
Time
P1 24
P2 3
P3 3
Suppose that the processes arrive in the order: P2 ,
P3 , P1
The Gantt Chart for the schedule is:
P2 P3 P
0

Turnaround Time
��� ���� ����

30 3 6
Average turnaround time: (30 + 3 + 6)/3 =
13
©Ahmed Operating 79
Hagag Systems
Scheduling Algorithms
1. First-Come, First-Served (FCFS) Scheduling
Process Burst
Time
P1 24
P2 3
P3 3
Suppose that the processes arrive in the order: P2 ,
P3 , P1
The Gantt Chart for the schedule is:
P2 P3 P
0

Response Time
��� ��� ����
� �
©Ahmed Operating 80
Hagag Systems
Scheduling Algorithms
1. First-Come, First-Served (FCFS) Scheduling
Process Burst
Time
P1 24
P2 3
P3 3
Suppose that the processes arrive in the order: P2 ,
P3 , P1
The Gantt Chart for the schedule is:
P2 P3 P
0

Response Time
���� ���� ����
6 0 3

Average response time: (6 + 0 + 3)/3


=3
©Ahmed Operating 81
Hagag Systems
Scheduling Algorithms

1. First-Come, First-Served (FCFS) Scheduling


• FCFS is fair in the formal sense or human sense of
fairness.
• but it is unfair in the sense that long jobs take
priority over short jobs and unimportant jobs make
important jobs wait.
• One of the major drawbacks of this scheme is that
the waiting time and the average turnaround time is
often quite long.
©Ahmed Operating 82
Hagag Systems
Scheduling Algorithms
2. Shortest-Job-First (SJF) Scheduling
• Associate with each process the length of its next
CPU burst.
 Use these lengths to schedule the p
rocess with the shortest time.
• SJF is optimal – gives minimum
average waiting time for a given set of
processes.
 The difficulty is knowing the length
of the next CPU request.
 Could ask the user.
©Ahmed Operating 83
Hagag Systems
Scheduling Algorithms
2.1 Shortest-Job-First (SJF)
Scheduling Process Burst
Time
P1 6
P2 8
P3 7
P4 3
SJF scheduling
chart

©Ahmed Operating 84
Hagag Systems
Scheduling Algorithms
2.1 Shortest-Job-First (SJF)
Scheduling Process Burst
Time
P1 6
P2 8
P3 7
P4 3
SJF scheduling
chart

P4 P1 P3 P2
0 3 9 16 24

©Ahmed Operating 85
Hagag Systems
Scheduling Algorithms
2.1 Shortest-Job-First (SJF)
Scheduling Process Burst
Time
P1 6
P2 8
P3 7
P4 3
SJF scheduling
chart

P4 P1 P3 P2
0 3 9 16 24

©Ahmed Operating 86
Hagag Systems
Scheduling Algorithms
2.1 Shortest-Job-First (SJF)
Scheduling Process Burst
Time
P1 6
P2 8
P3 7
P4 3
SJF scheduling
chart

P4 P1 P3 P2
0 3 9 16 2
4

©Ahmed Operating 87
Hagag Systems
Scheduling Algorithms
2.1 Shortest-Job-First (SJF)
Scheduling Process Burst
Time
P1 6
P2 8
P3 7
P4 3
SJF scheduling
chart

P4 P1 P3 P2

0 3 9 16 24

©Ahmed Operating 88
Hagag Systems
Scheduling Algorithms
2.1 Shortest-Job-First (SJF)
Scheduling Process Burst
Time
P1 6
P2 8
P3 7
P 3
SJF scheduling4
chart
P4 P1 P3 P2

0 3 9 16 24

Waiting Time
�� �� �� ��
�� �� �� ��

©Ahmed Operating 89
Hagag Systems
Scheduling Algorithms
2.1 Shortest-Job-First (SJF)
Scheduling Process Burst
Time
P1 6
P2 8
P3 7
P 3
SJF scheduling4
chart
P4 P1 P3 P2

0 3 9 16 24

Waiting Time
��� �� ���� ����
� ��
3 16 9 0
Average waiting time: (3 + 16 + 9 + 0)/4 =
7
©Ahmed Operating 90
Hagag Systems
Scheduling Algorithms
2.1 Shortest-Job-First (SJF)
Scheduling Process Burst
Time
P1 6
P2 8
P3 7
P 3
SJF scheduling4
chart
P4 P1 P3 P2

0 3 9 16 24

Turnaround Time
�� �� �� ��
�� �� �� ��

©Ahmed Operating 91
Hagag Systems
Scheduling Algorithms
2.1 Shortest-Job-First (SJF)
Scheduling Process Burst
Time
P1 6
P2 8
P3 7
P 3
SJF scheduling4
chart
P4 P1 P3 P2

0 3 9 16 24

Turnaround Time
��� �� �� ����
� �� ��
9 24 16 3
Average Turnaround time: (9 + 24 + 16 + 3)/4 =
13
©Ahmed Operating 92
Hagag Systems
Scheduling Algorithms
2.1 Shortest-Job-First (SJF)
Scheduling Process Burst
Time
P1 6
P2 8
P3 7
P 3
SJF scheduling4
chart
P4 P1 P3 P2

0 3 9 16 24

Response Time
�� �� �� ��
�� �� �� ��

©Ahmed Operating 93
Hagag Systems
Scheduling Algorithms
2.1 Shortest-Job-First (SJF)
Scheduling Process Burst
Time
P1 6
P2 8
P3 7
P 3
SJF scheduling4
chart
P4 P1 P3 P2

0 3 9 16 24

Response Time
��� �� ���� ����
� ��
3 16 9 0
Average Response time: (3 + 16 + 9 + 0)/4
=7
©Ahmed Operating 94
Hagag Systems
Scheduling Algorithms
2.1 Shortest-Job-First (SJF) (Non-Preemptive SJF )
Now we add the concepts of varying arrival times and
preemption to the analysis
Process Arrival Time Burst
Time
P1 0 1
P2 1 4
P3 2 7
P4 3 5
Non-Preemptive SJF Gantt
Chart

©Ahmed Operating 95
Hagag Systems
Scheduling Algorithms
2.1 Shortest-Job-First (SJF) (Non-Preemptive SJF )
Now we add the concepts of varying arrival times and
preemption to the analysis
Process Arrival Time Burst
Time
P1 0 1
P2 1 4
P3 2 7
P4 3 5
Non-Preemptive SJF Gantt
Chart
P1 P2 P4 P1 P3
0 1 5 10 17 26

©Ahmed Operating 96
Hagag Systems
Scheduling Algorithms
2.1 Shortest-Job-First (SJF) (Non-Preemptive SJF )
Now we add the concepts of varying arrival times and
preemption to the analysis
Process Arrival Time Burst
Time
P1 0 1
P2 1 4
P3 2 7
P4 3 5
Non-Preemptive SJF Gantt
Chart
P1 P2 P4 P1 P3
0 1 5 10 17 26

©Ahmed Operating 97
Hagag Systems
Scheduling Algorithms
2.1 Shortest-Job-First (SJF) (Non-Preemptive SJF )
Now we add the concepts of varying arrival times and
preemption to the analysis
Process Arrival Time Burst
Time
P1 0 1
P2 1 4
P3 2 7
P4 3 5
Non-Preemptive SJF Gantt
Chart
P1 P2 P4 P1 P3
0 1 5 10 17 26

©Ahmed Operating 98
Hagag Systems
Scheduling Algorithms
2.1 Shortest-Job-First (SJF) (Non-Preemptive SJF )
Now we add the concepts of varying arrival times and
preemption to the analysis
Process Arrival Time Burst
Time
P1 0 1
P2 1 4
P3 2 7
P4 3 5
Non-Preemptive SJF Gantt
Chart

©Ahmed Operating 99
Hagag Systems
Scheduling Algorithms
2.1 Shortest-Job-First (SJF) (Non-Preemptive SJF )
Now we add the concepts of varying arrival times and
preemption to the analysis
Process Arrival Time Burst
Time
P1 0 1
P2 1 4
P3 2 7
P4 3 5
Non-Preemptive SJF Gantt
Chart
Waiting Time
��� ��� ���� ���
� � �

©Ahmed Operating 100


Hagag Systems
Scheduling Algorithms
2.1 Shortest-Job-First (SJF) (Non-Preemptive SJF )
Now we add the concepts of varying arrival times and
preemption to the analysis
Process Arrival Time Burst
Time
P1 0 1
P2 1 4
P3 2 7
P4 3 5
Non-Preemptive SJF Gantt
Chart
Waiting Time
���� ���� ���� ����
(0 − 0) (1 − 1) (10 − 2) (5 − 3)

Average waiting time: (0 + 0 + 8 + 2)/4 = 2.5


msec
©Ahmed Operating 101
Hagag Systems
Scheduling Algorithms
2.1 Shortest-Job-First (SJF) (Non-Preemptive SJF )
Now we add the concepts of varying arrival times and
preemption to the analysis
Process Arrival Time Burst
Time
P1 0 1
P2 1 4
P3 2 7
P4 3 5
Non-Preemptive SJF Gantt
Chart
Turnaround Time
��� ��� ���� ����
� �

©Ahmed Operating 102


Hagag Systems
Scheduling Algorithms
2.1 Shortest-Job-First (SJF) (Non-Preemptive SJF )
Now we add the concepts of varying arrival times and
preemption to the analysis
Process Arrival Time Burst
Time
P1 0 1
P2 1 4
P3 2 7
P4 3 5
Non-Preemptive SJF Gantt
Chart
Turnaround Time
���� ���� ���� ����
(1 − 0) (5 − 1) (17 − 2) (10 − 3)

Average Turnaround time: (1 + 4 + 15 + 7)/4 = 6.75


msec
©Ahmed Operating 103
Hagag Systems
Scheduling Algorithms
2.1 Shortest-Job-First (SJF) (Non-Preemptive SJF )
Now we add the concepts of varying arrival times and
preemption to the analysis
Process Arrival Time Burst
Time
P1 0 1
P2 1 4
P3 2 7
P4 3 5
Non-Preemptive SJF Gantt
Chart
Response Time
��� ��� ���� ���
� � �

©Ahmed Operating 104


Hagag Systems
Scheduling Algorithms
2.1 Shortest-Job-First (SJF) (Non-Preemptive SJF )
Now we add the concepts of varying arrival times and
preemption to the analysis
Process Arrival Time Burst
Time
P1 0 1
P2 1 4
P3 2 7
P4 3 5
Non-Preemptive SJF Gantt
Chart
Response Time
���� ���� ���� ����
(0 − 0) (1 − 1) (10 − 2) (5 − 3)

Average Response time: (0 + 0 + 8 + 2)/4 = 2.5


msec
©Ahmed Operating 105
Hagag Systems
Scheduling Algorithms
Determining Length of Next CPU Burst
Can only estimate the length – should be similar to the previous one
Then pick process with shortest predicted next CPU burst

Can be done by using the length of previous CPU bursts, using


exponential averaging
1. t n  actual length of thn CPU burst

2.n1 predicted value for the next CPU burst 3. , 0   1

4. Define : n 1
 t n
 1
n
 .
Commonly, set to ½
Preemptive version called shortest-remaining-time-
©Ahmed
f irst Operating 106
Hagag Systems
Scheduling Algorithms
Prediction of the Length of the Next CPU
Burst

©Ahmed Operating 107


Hagag Systems
Scheduling Algorithms
2.2 Shortest-remaining-time-f irst (Preemptive SJF )
Now we add the concepts of varying arrival times and
preemption to the analysis
Process Arrival Time Burst
Time
P1 0 8
P2 1 4
P3 2 9
P 3 5
Preemptive 4SJF Gantt
Chart

©Ahmed Operating 108


Hagag Systems
Scheduling Algorithms
2.2 Shortest-remaining-time-f irst (Preemptive SJF )
Now we add the concepts of varying arrival times and
preemption to the analysis
Proces Arrival Time Burst
s Time
P1 P2 0 8
P3 P4 1 4
2 9
0m
Preemptive SJF Gantt 3 5 s
Chart

©Ahmed Operating 109


Hagag Systems
Scheduling Algorithms
2.2 Shortest-remaining-time-f irst (Preemptive SJF )
Now we add the concepts of varying arrival times and
preemption to the analysis
ProcesArrival Time Burst
s Time
P1 P2 0 8
P3 P4 1 4
2 9
0m
Preemptive SJF Gantt 3 5 s
Chart
P1 P2 P4 P1 P3
0 1 5 10 17 26

©Ahmed Operating 110


Hagag Systems
Scheduling Algorithms
2.2 Shortest-remaining-time-f irst (Preemptive SJF )
Now we add the concepts of varying arrival times and
preemption to the analysis
Process Arrival Time Burst Time
P1 0 87
P2 1 4
P3 2 9
P4 3 5 1m
Preemptive SJF Gantt s
Chart
P1 P2 P4 P1 P3
0 1 5 10 17 26

©Ahmed Operating 111


Hagag Systems
Scheduling Algorithms
2.2 Shortest-remaining-time-f irst (Preemptive SJF )
Now we add the concepts of varying arrival times and
preemption to the analysis
Process Arrival Time Burst Time
P1 0 87
P2 1 43
P3 2 9
P4 3 5 2m
Preemptive SJF Gantt s
Chart
P1 P2 P4 P1 P3
0 1 2 3 5 10 17 26

©Ahmed Operating 112


Hagag Systems
Scheduling Algorithms
2.2 Shortest-remaining-time-f irst (Preemptive SJF )
Now we add the concepts of varying arrival times and
preemption to the analysis
Process Arrival Time Burst Time
P1 0 87
P2 1 43 2
P3 2 9
P4 3 5 3m
Preemptive SJF Gantt s
Chart
P4 P1 P3
P1 P2
0 1 2 5 10 17 26

©Ahmed Operating 113


Hagag Systems
Scheduling Algorithms
2.2 Shortest-remaining-time-f irst (Preemptive SJF )
Now we add the concepts of varying arrival times and
preemption to the analysis
Process Arrival Time Burst Time
P1 0 87
P2 1 43 2
P3 2 9
P4 3 5 3m
Preemptive SJF Gantt s
Chart
P4 P1 P3
P1 P2
0 1 2 5 10 17 26

©Ahmed Operating 114


Hagag Systems
Scheduling Algorithms
2.2 Shortest-remaining-time-f irst (Preemptive SJF )
Now we add the concepts of varying arrival times and
preemption to the analysis
Process Arrival Time Burst Time
P1 0 87
P2 1 43 2
P3 2 9
P4 3 5 5m
Preemptive SJF Gantt s
Chart
P1 P2 P4 P1 P3
0 1 5 10 17 26

©Ahmed Operating 115


Hagag Systems
Scheduling Algorithms
2.2 Shortest-remaining-time-f irst (Preemptive SJF )
Now we add the concepts of varying arrival times and
preemption to the analysis
Process Arrival Time Burst Time
P1 0 87
P2 1 43 2
P3 2 9
P4 3 5 10
Preemptive SJF Gantt ms
Chart
P1 P2 P4 P1 P3
0 1 5 10 17 26

©Ahmed Operating 116


Hagag Systems
Scheduling Algorithms
2.2 Shortest-remaining-time-f irst (Preemptive SJF )
Now we add the concepts of varying arrival times and
preemption to the analysis
Process Arrival Time Burst Time
P1 0 87
P2 1 43 2
P3 2 9
P4 3 5 17
Preemptive SJF Gantt ms
Chart
P1 P2 P4 P1 P3
0 1 5 10 17 2
6

©Ahmed Operating 117


Hagag Systems
Scheduling Algorithms
2.2 Shortest-remaining-time-f irst (Preemptive SJF )
Now we add the concepts of varying arrival times and
preemption to the analysis
Process Arrival Time Burst Time
P1 0 87
P2 1 43 2
P3 2 9
P4 3 5 26
Preemptive SJF Gantt ms
Chart
P1 P2 P4 P1 P3
0 1 5 10 17 26

©Ahmed Operating 118


Hagag Systems
Scheduling Algorithms
2.2 Shortest-remaining-time-f irst (Preemptive SJ
F) Process Arrival Time Burst
Time
P1 0 8
P2 1 4
P3 2 9
P4 3 5
Preemptive SJF Gantt
Chart
P1 P2 P4 P1 P3
0 1 5 10 17 26

Waiting Time
��� ��� ���� ���
� � �

©Ahmed Operating 119


Hagag Systems
Scheduling Algorithms
2.2 Shortest-remaining-time-f irst (Preemptive SJ
F) Process Arrival Time Burst
Time
P1 0 8
P2 1 4
P3 2 9
P4 3 5
Preemptive SJF Gantt
Chart
P1 P2 P4 P1 P3
0 1 5 10 17 26

Waiting Time
���� ���� ���� ����
10 − 1 1 −1 17 − 2 5−3
= �� = �� = ���� = �� Average waiting time = [9+0+15+2]/4 = 26/4 = 6.5
msec
©Ahmed Operating 120
Hagag Systems
Scheduling Algorithms
2.2 Shortest-remaining-time-f irst (Preemptive SJ
F) Process Arrival Time Burst
Time
P1 0 8
P2 1 4
P3 2 9
P4 3 5
Preemptive SJF Gantt
Chart
P1 P2 P4 P1 P3
0 1 5 10 17 26

Turnaround Time
��� ��� ���� ���
� � �

©Ahmed Operating 121


Hagag Systems
Scheduling Algorithms
2.2 Shortest-remaining-time-f irst (Preemptive SJ
F) Process Arrival Time Burst
Time
P1 0 8
P2 1 4
P3 2 9
P4 3 5
Preemptive SJF Gantt
Chart
P1 P2 P4 P1 P3
0 1 5 10 17 26

Turnaround Time
���� ���� ���� ����
17 − 0 5 −1 26 − 2 10 − 3
= ��� = �� = ���� = �� Average turnaround time = [17+4+24+7]/4 = 52/4 = 13
� msec
©Ahmed Operating 122
Hagag Systems
Scheduling Algorithms
2.2 Shortest-remaining-time-f irst (Preemptive SJ
F) Process Arrival Time Burst
Time
P1 0 8
P2 1 4
P3 2 9
P4 3 5
Preemptive SJF Gantt
Chart
P1 P2 P4 P1 P3
0 1 5 10 17 26

Response Time
��� ��� ���� ���
� � �

©Ahmed Operating 123


Hagag Systems
Scheduling Algorithms
2.2 Shortest-remaining-time-f irst (Preemptive SJ
F) Process Arrival Time Burst
Time
P1 0 8
P2 1 4
P3 2 9
P4 3 5
Preemptive SJF Gantt
Chart
P1 P2 P4 P1 P3
0 1 5 10 17 26

Response Time
���� ���� ���� ����
0−0 1 −1 17 − 2 5−3
= �� = �� = ���� = �� Average response time = [0+0+15+2]/4 = 17/4 = 4.25
msec
©Ahmed Operating 124
Hagag Systems
Scheduling Criteria
• CPU utilization – keep the CPU as busy as possible.
• Throughput – #of processes that complete their execution per time unit.
• Turnaround time – amount of time to execute a particular process. (time
from submission to termination)
• 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 f irst response is produced, not output.

©Ahmed Operating 125


Hagag Systems
Scheduling Criteria
Scheduling Algorithm Optimization
Criteria

• Max CPU utilization.


• Max throughput.
• Min turnaround time.
• Min waiting time.
• Min response time.

©Ahmed Operating 126


Hagag Systems
Scheduling Algorithms
• There are many different CPU-scheduling
algorithms:
1. First Come, First Served (FCFS).
2. Shortest Job First (SJF).
 Preemptive SJF.
 Non-Preemptive SJF.
3. Priority.
4. Round Robin.
5. Multilevel queues.

©Ahmed Operating 127


Hagag Systems
Scheduling Algorithms
3. Priority Scheduling
A priority number (integer) is associated with each process

The CPU is allocated to the process with the highest priority (smallest integer
 highest priority)
Preemptive
Nonpreemptive

SJF is priority scheduling where priority is the inverse of predicted next CPU
burst time

Problem  Starvation – low priority processes may never execute

Solution  Aging – as time progresses increase the priority of the process

©Ahmed Operating 128


Hagag Systems
Scheduling Algorithms
3. Priority Scheduling
Process Burst Time Priority
P1 10 3
P2 1 1
P3 2 4
P4 1 5
P5 5 2
Priority scheduling Gantt
Chart

©Ahmed Operating 129


Hagag Systems
Scheduling Algorithms
3. Priority Scheduling
Process Burst Time Priority
P1 10 3
P2 1 1 Highest
priority
P3 2 4
P4 1 5
P5 5 2
Priority scheduling Gantt
Chart

©Ahmed Operating 130


Hagag Systems
Scheduling Algorithms
3. Priority Scheduling
Process Burst Time Priority
P1 10 3
P2 1 1
P3 2 4
P4 1 5
P5 5 2
Priority scheduling Gantt
Chart

©Ahmed Operating 131


Hagag Systems
Scheduling Algorithms
3. Priority Scheduling
Process Burst Time Priority
P1 10 3
P2 1 1
P3 2 4
P4 1 5
P5 5 2
Priority scheduling Gantt
Chart

©Ahmed Operating 132


Hagag Systems
Scheduling Algorithms
3. Priority Scheduling
Process Burst Time Priority
P1 10 3
P2 1 1
P3 2 4
P4 1 5
P5 5 2
Priority scheduling Gantt
Chart

©Ahmed Operating 133


Hagag Systems
Scheduling Algorithms
3. Priority Scheduling
Process Burst Time Priority
P1 10 3
P2 1 1
P3 2 4
P4 1 5
P5 5 2
Priority scheduling Gantt
Chart

©Ahmed Operating 134


Hagag Systems
Scheduling Algorithms
3. Priority Scheduling
Process Burst Time Priority
P1 10 3
P2 1 1
P3 2 4
P4 1 5
P5 5 2
Priority scheduling Gantt
Chart

©Ahmed Operating 135


Hagag Systems
Scheduling Algorithms
3. Priority Scheduling
Process Burst Time Priority
P1 10 3
P2 1 1
P3 2 4
P4 1 5
P5 5 2
Priority scheduling Gantt
Chart

Waiting Time
�� �� �� �� ���
�� �� �� �� �

©Ahmed Operating 136


Hagag Systems
Scheduling Algorithms
3. Priority Scheduling
Process Burst Time Priority
P1 10 3
P2 1 1
P3 2 4
P4 1 5
P5 5 2
Priority scheduling Gantt
Chart

Waiting Time
���� ��� �� �� ���
� �� �� � Average Waiting time = [6+0+16+18+1]/5 = 8.2
6 0 16 18 1 msec

©Ahmed Operating 137


Hagag Systems
Scheduling Algorithms
3. Priority Scheduling
Process Burst Time Priority
P1 10 3
P2 1 1
P3 2 4
P4 1 5
P5 5 2
Priority scheduling Gantt
Chart

Turnaround Time
�� �� �� �� ���
�� �� �� �� �

©Ahmed Operating 138


Hagag Systems
Scheduling Algorithms
3. Priority Scheduling
Process Burst Time Priority
P1 10 3
P2 1 1
P3 2 4
P4 1 5
P5 5 2
Priority scheduling Gantt
Chart

Turnaround Time
�� ��� �� �� ���
�� � �� �� � Average Turnaround time = [16+1+18+19+6]/5 = 12
16 1 18 19 6 msec

©Ahmed Operating 139


Hagag Systems
Scheduling Algorithms
3. Priority Scheduling
Process Burst Time Priority
P1 10 3
P2 1 1
P3 2 4
P4 1 5
P5 5 2
Priority scheduling Gantt
Chart

Response Time
�� �� �� �� ���
�� �� �� �� �

©Ahmed Operating 140


Hagag Systems
Scheduling Algorithms
3. Priority Scheduling
Process Burst Time Priority
P1 10 3
P2 1 1
P3 2 4
P4 1 5
P5 5 2
Priority scheduling Gantt
Chart

Response Time
���� ��� �� �� ���
� �� �� � Average Response time = [6+0+16+18+1]/5 = 8.2
6 0 16 18 1 msec

©Ahmed Operating 141


Hagag Systems
Scheduling Algorithms
4. Round Robin (RR) Scheduling
Each process gets a small unit of CPU time (time quantum
q ), usually 10-100 milliseconds. After this time has
elapsed, the process is preempted and added to the end
of the ready queue.
If there are ��processes in the ready queue and the time
quantum is ��, then each process gets 1/�� of the
CPU time in chunks of at most ��time units at once.
No process waits more than (�� − 1)�� time units.

©Ahmed Operating 142


Hagag Systems
Scheduling Algorithms
4. Round Robin (RR) Scheduling

©Ahmed Operating 143


Hagag Systems
Scheduling Algorithms
4. Round Robin (RR) Scheduling
Process Burst
Time
P1 24
P2 3
P3 3
All the processes arrive at the same time 0.
Round Robin (RR) scheduling of quantum: 4
ms

©Ahmed Operating 144


Hagag Systems
Scheduling Algorithms
4. Round Robin (RR) Scheduling
Process Burst
Time
P1 24
P2 3
P3 3
All the processes arrive at the same time 0.
Round Robin (RR) scheduling of quantum: 4
ms
P1 P2 P3 P1 P1 P1 P1 P1

0 4 7 10 14 18 22 26 30

©Ahmed Operating 145


Hagag Systems
Scheduling Algorithms
4. Round Robin (RR) Scheduling
Process Burst
Time
P1 24
P2 3
P3 3
All the processes arrive at the same time 0.
Round Robin (RR) scheduling of quantum: 4
ms
P1 P2 P3 P1 P1 P1 P1 P1

0 4 10 14 18 22 26 30
7

©Ahmed Operating 146


Hagag Systems
Scheduling Algorithms
4. Round Robin (RR) Scheduling
Process Burst
Time
P1 24
P2 3
P3 3
All the processes arrive at the same time 0.
Round Robin (RR) scheduling of quantum: 4
ms
P1 P2 P3 P1 P1 P1 P1 P1

0 4 7 10 14 18 22 26 30

©Ahmed Operating 147


Hagag Systems
Scheduling Algorithms
4. Round Robin (RR) Scheduling
Process Burst
Time
P1 24
P2 3
P3 3
All the processes arrive at the same time 0.
Round Robin (RR) scheduling of quantum: 4
ms
P1 P2 P3 P1 P1 P1 P1 P1

0 4 7 10 14 18 22 26 30

©Ahmed Operating 148


Hagag Systems
Scheduling Algorithms
4. Round Robin (RR) Scheduling
Process Burst
Time
P1 24
P2 3
P3 3
All the processes arrive at the same time 0.
Round Robin (RR) scheduling of quantum: 4
ms
P1 P2 P3 P1 P1 P1 P1 P1

0 4 7 10 14 18 22 26 30

©Ahmed Operating 149


Hagag Systems
Scheduling Algorithms
4. Round Robin (RR) Scheduling
Process Burst
Time
P1 24
P2 3
P3 3
All the processes arrive at the same time 0.
Round Robin (RR) scheduling of quantum: 4
ms
P1 P2 P3 P1 P1 P1 P1 P1
0 4 7 10 14 18 22 26 30

©Ahmed Operating 150


Hagag Systems
Scheduling Algorithms
4. Round Robin (RR) Scheduling
Process Burst
Time
P1 24
P2 3
P3 3
All the processes arrive at the same time 0.
Round Robin (RR) scheduling of quantum: 4
ms
P1 P2 P3 P1 P1 P1 P1 P1
0 4 7 10 14 18 22 26 30

©Ahmed Operating 151


Hagag Systems
Scheduling Algorithms
4. Round Robin (RR) Scheduling
Process Burst
Time
P1 24
P2 3
P3 3
All the processes arrive at the same time 0.
Round Robin (RR) scheduling of quantum: 4
ms
P1 P2 P3 P1 P1 P1 P1 P1
0 4 7 10 14 18 22 26 30

©Ahmed Operating 152


Hagag Systems
Scheduling Algorithms
4. Round Robin (RR) Scheduling
Process Burst
Time
P1 24
P2 3
P3 3
All the processes arrive at the same time 0.
Round Robin (RR) scheduling of quantum: 4
ms
P1 P2 P3 P1 P1 P1 P1 P1
0 4 7 10 14 18 22 26 30

©Ahmed Operating 153


Hagag Systems
Scheduling Algorithms
4. Round Robin (RR) Scheduling
Process Burst
Time
P1 24
P2 3
P3 3
All the processes arrive at the same time 0.
Round Robin (RR) scheduling of quantum: 4
ms
P1 P2 P3 P1 P1 P1 P1 P1
0 4 7 10 14 18 22 26 30

# of context switches =
??

©Ahmed Operating 154


Hagag Systems
Scheduling Algorithms
4. Round Robin (RR) Scheduling
Process Burst
Time
P1 24
P2 3
P3 3
All the processes arrive at the same time 0.
Round Robin (RR) scheduling of quantum: 4
ms
P1 P2 P3 P1 P1 P1 P1 P1
0 4 7 10 14 18 22 26 30

# of context switches
=7

©Ahmed Operating 155


Hagag Systems
Scheduling Algorithms
4. Round Robin (RR) Scheduling
Process Burst
Time
P1 24
P2 3
All the processes arrive atP3the same time 0.
3
Round Robin (RR) scheduling of quantum: 4
ms
P1 P2 P3 P1 P1 P1 P1 P1
0 4 7 10 14 18 22 26 30

Waiting Time
���� ��� ���
� �

©Ahmed Operating 156


Hagag Systems
Scheduling Algorithms
4. Round Robin (RR) Scheduling
Process Burst
Time
P1 24
P2 3
All the processes arrive atP3the same time 0.
3
Round Robin (RR) scheduling of quantum: 4
ms
P1 P2 P3 P1 P1 P1 P1 P1
0 4 7 10 14 18 22 26 30

Waiting Time
���� ���� ����
0 + (10 − 4) 4 7

Average waiting time: (6 + 4 + 7)/3 = 5.667


ms
©Ahmed Operating 157
Hagag Systems
Scheduling Algorithms
4. Round Robin (RR) Scheduling
Process Burst
Time
P1 24
P2 3
All the processes arrive atP3the same time 0.
3
Round Robin (RR) scheduling of quantum: 4
ms
P1 P2 P3 P1 P1 P1 P1 P1
0 4 7 10 14 18 22 26 30

Turnaround Time
���� ��� ���
� �

©Ahmed Operating 158


Hagag Systems
Scheduling Algorithms
4. Round Robin (RR) Scheduling
Process Burst
Time
P1 24
P2 3
All the processes arrive atP3the same time 0.
3
Round Robin (RR) scheduling of quantum: 4
ms
P1 P2 P3 P1 P1 P1 P1 P1
0 4 7 10 14 18 22 26 30

Turnaround Time
���� ���� ���

30 7 10
Average Turnaround time: (30 + 7 + 10)/3 = 15.667
ms
©Ahmed Operating 159
Hagag Systems
Scheduling Algorithms
4. Round Robin (RR) Scheduling
Process Burst
Time
P1 24
P2 3
All the processes arrive atP3the same time 0.
3
Round Robin (RR) scheduling of quantum: 4
ms
P1 P2 P3 P1 P1 P1 P1 P1
0 4 7 10 14 18 22 26 30

Response Time
���� ��� ���
� �

©Ahmed Operating 160


Hagag Systems
Scheduling Algorithms
4. Round Robin (RR) Scheduling
Process Burst
Time
P1 24
P2 3
All the processes arrive atP3the same time 0.
3
Round Robin (RR) scheduling of quantum: 4
ms
P1 P2 P3 P1 P1 P1 P1 P1
0 4 7 10 14 18 22 26 30

Response Time
���� ���� ����
0 4 7

Average Response time: (0 + 4 + 7)/3 = 3.667


ms
©Ahmed Operating 161
Hagag Systems
Scheduling Algorithms
• There are many different CPU-scheduling
algorithms:
1. First Come, First Served (FCFS).
2. Shortest Job First (SJF).
 Preemptive SJF.
 Non-Preemptive SJF.
3. Priority.
4. Round Robin.
5. Multilevel queues.

©Ahmed Operating 162


Hagag Systems
Scheduling Algorithms
5. Multilevel Queue Scheduling
Ready queue is partitioned into separate
queues, eg:
foreground (interactive)
background (batch)
Process permanently in a given queue
Each queue has its own scheduling algorithm:
foreground – RR.
background – FCFS.

©Ahmed Operating 163


Hagag Systems
Scheduling Algorithms
5. Multilevel Queue Scheduling
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.

©Ahmed Operating 164


Hagag Systems
Scheduling Algorithms
5. Multilevel Queue
Scheduling

©Ahmed Operating 165


Hagag Systems
Scheduling Algorithms
5. Multilevel Queue Scheduling
Three queues:
Q0 – RR with time quantum 8
milliseconds
Q1 – RR time quantum 16 milliseconds
Q2 – FCFS

©Ahmed Operating 166


Hagag Systems
Scheduling Algorithms
5. Multilevel Queue Scheduling
Scheduling
A new job enters queue ��0which is served FCFS
When it gains CPU, job receives 8 milliseconds.
If it does not finish in 8 milliseconds, job is moved to queue ��1.

At ��1 job is again served FCFS and receives 16 additional


milliseconds
If it still does not complete, it is preempted and moved to queue �
�2.

©Ahmed Operating 167


Hagag Systems
Scheduling Algorithms
5. Multilevel Queue Scheduling
Now we add the concepts of varying arrival times and
preemption to the analysis
Process Arrival Time Burst
Time
P1 0 7
P2 1 60
P3 2 20
P4 3 40

Multilevel Queue Fixed


priority
non-preemptive

©Ahmed Operating 168


Hagag Systems
Scheduling Algorithms

5. Multilevel Queue �
SchedulingProces Arrival Time Burst 0

s Time 0 7 �
P1 P2 1 60 1

P �
3 2 20 �
P4 3 40 2


�0


�1


©Ahmed �2 Operating 169
Hagag Systems
Scheduling Algorithms

5. Multilevel Queue �
SchedulingProcess Arrival Time Burst 0

Time
�1
P1 0 7
P2 1 60
3 �
P 2 20
�2
P4 3 40

7m 7ms
s
� ��1

0

�1



©Ahmed Operating 170
Hagag 2 Systems
Scheduling Algorithms

5. Multilevel Queue �
SchedulingProcess Arrival Time Burst 0

Time
�1
P1 0 7
P2 1 60
3 �
P 2 20
�2
P4 3 40

7m
� s
�0 7ms 8ms
��1 ��2

�1


©Ahmed �2 Operating 171
Hagag Systems
Scheduling Algorithms

5. Multilevel Queue �
SchedulingProces Arrival Time Burst 0

s Time 0 7 �
P1 P2 1 60 1

P �
3 2 �
P4 52
3 2
20
15m 40
7m 8m s
s s
� ��1 ��2

0

�1



©Ahmed Operating 172
Hagag 2 Systems
Scheduling Algorithms

5. Multilevel Queue �
SchedulingProces Arrival Time Burst 0

s Time 0 7 �
P1 P2 1 60 1

P �
3 2 �
P4 52
3 2
20
15m 40
7m 8m s 8m
s s s
� ��1 ��2 ��3

0
� ��2

1


2
©Ahmed Operating 173
Hagag Systems
Scheduling Algorithms
5. Multilevel Queue Scheduling
��0
Process Arrival Time Burst Time
P1 0 7
��1 P2 1 60 52 44
P3 2 20 12
��2 P4 3 40

23ms
7m 8m 8m
s s s
� ��1 ��2 ��3

0
� ��2

1


2
©Ahmed Operating 174
Hagag Systems
Scheduling Algorithms
5. Multilevel Queue
SchedulingProcess Arrival Time Burst Time
��0 P1 0 7
P2 1 60 52 44
��1 P3 2 20 12
P4 3 40
��2
23ms
7ms 8ms 8ms 8ms
� ��1 ��2 ��3 �
�0 �4

� ��2
�1


©Ahmed �2 Operating 175
Hagag Systems
Scheduling Algorithms
5. Multilevel Queue Scheduling
��0
Process Arrival Time Burst Time
P1 0 7
��1 P2 1 60 52 44 36
P3 2 20 12
��2 P4 3 40 32

31ms
7m 8m 8m 8m
s s s s
� ��1 ��2 ��3 ��4

16ms
0
� ��2

1


2
©Ahmed Operating 176
Hagag Systems
Scheduling Algorithms
5. Multilevel Queue Scheduling
��0
Process Arrival Time Burst Time
P1 0 7
��1 P2 1 60 52 44 36
P3 2 20 12
��2 P4 3 40 32

31ms
7m 8m 8m 8m
s s s s
� ��1 ��2 ��3 ��4

16ms 12ms
0
� ��2 ��3

36ms
1
� �
� �
2
©Ahmed Operating 2
177
Hagag Systems
Scheduling Algorithms
5. Multilevel Queue

Scheduling

Proces Arrival Time Burst
s Time 0 7
0
� P1 P2 1 60 52 4

P3 P4 2 4 36 2
1
� 4
3
� 20 12
2 43 m 40 32
7m 8m 8m 8m s
s s s s
� ��1 ��2 ��3 ��4

16m 12m
0 s s
� ��2 ��3

36ms
1
� ��2

2
©Ahmed Operating 178
Hagag Systems
Scheduling Algorithms
5. Multilevel Queue

Scheduling

Proces Arrival Time Burst
s Time 0 7
0
� P1 P2 1 60 52 4

P3 P4 2 4 36 2
1
� 4
3
� 20 12
2 43 m 40 32
7m 8m 8m 8m s
s s s s
� ��1 ��2 ��3 ��4

16m 12m 16ms
0 s s
� ��2 ��3 ��4

36ms
1
� ��2

2
©Ahmed Operating 179
Hagag Systems
Scheduling Algorithms
5. Multilevel Queue Scheduling
��0
Process Arrival Time Burst Time
P1 0 7
��1 P2 1 60 52 44 36 24 8
P3 2 20 12
��2 P4 3 40 32 16

59ms
7m 8m 8m 8m
s s s s
� ��1 ��2 ��3 ��4

16m 12m 16m
0 s s s
� ��2 ��3 ��4

36ms
1
� �
� �
2
©Ahmed Operating 2
180
Hagag Systems
Scheduling Algorithms
5. Multilevel Queue

Scheduling

Proces Arrival Time Burst
s Time 0 7
0
� P1 P2 1 60 52 44

P3 P4 2 36 24
1
� 8
3
� 20 12
2
40 32 67m16
7m 8m 8m 8m s
s s s s
� ��1 ��2 ��3 ��4

16m 12m 16m
0 s s s
� ��2 ��3 ��4

36ms
1
� �
� �
2
©Ahmed Operating 2
181
Hagag Systems
Scheduling Algorithms
5. Multilevel Queue

Scheduling

Proces Arrival Time Burst
s Time 0 7
0
� P1 P2 1 60 52 44

P3 P4 2 36 24
1
� 8
3
� 20 12
2
40 32 67m16
7m 8m 8m 8m s
s s s s
� ��1 ��2 ��3 ��4

16m 12m 16m
0 s s s
� ��2 ��3 ��4

36ms 16ms
1
� � ��4
� �
2
©Ahmed Operating 2
182
Hagag Systems
Scheduling Algorithms
5. Multilevel Queue

Scheduling

Proces Arrival Time Burst
s Time 0 7
0
� P1 P2 1 60 52 44

P3 P4 2 36 24
1
� 8
3
� 20 12
2
40 32 16 83m
7m 8m 8m 8m s
s s s s
� ��1 ��2 ��3 ��4

16m 12m 16m
0 s s s
� ��2 ��3 ��4

36m 16m
1 s s
� � ��4
� �
2
©Ahmed Operating 2
183
Hagag Systems
Scheduling Algorithms
5. Multilevel Queue

Scheduling

Proces Arrival Time Burst
s Time 0 7
0
� P1 P2 1 60 52 44

P3 P4 2 36 24
1
� 8
3
� 20 12
2 7ms 15ms 23ms 43 m 40 59 32ms 16 83m

7m
s 31ms
8
s
m s
67ms s
��1 ��2 ��3 8��
8ms ms 4

16ms 12ms 16ms
0
� ��2 ��3 ��4

36ms 16ms
1
� ��2 ��4

2
©Ahmed Operating 184
Hagag Systems
Scheduling Algorithms
5. Multilevel Queue

Scheduling

Process Arrival
Waiting Time
Time
1 0
0
� �� ��� ���� ����
P
P2 1
� �� �

1
P3 2
� P4 3

2 7ms 15ms 23ms 43m 59ms 83m

7m
s 31ms
8
s
m s
67ms s
��1 ��2 ��3 8��
8ms ms 4

16ms 12ms 16ms
0
� ��2 ��3 ��4

36ms 16ms
1
� ��2 ��4

2
©Ahmed Operating 185
Hagag Systems
Scheduling Algorithms
5. Multilevel Queue

Scheduling

Process Arrival
Waiting Time
Time
1 0
0
� �� ��� ���� ����
P
P2 1
� �� �

1
P3 2 0
� P4 3 = �
� �
2 7ms 15ms 23ms 43m 59ms 83m

7m
s 31ms
8
s
m s
67ms s
��1 ��2 ��3 8��
8ms ms 4

16ms 12ms 16ms
0
� ��2 ��3 ��4

36ms 16ms
1
� ��2 ��4

2
©Ahmed Operating 186
Hagag Systems
Scheduling Algorithms
5. Multilevel Queue

Scheduling

Process Arrival
Waiting Time
Time
1 0
0
� �� ���� ���� ����
P
P2 1
� ��

1
P3 2 0 7−1
� P4 3 = � = ��
� �
2 7ms 15ms 23ms 43m 59ms 83m

7m
s 31ms
8
s
m s
67ms s
��1 ��2 ��3 8��
8ms ms 4

16ms 12ms 16ms
0
� ��2 ��3 ��4

36ms 16ms
1
� ��2 ��4

2
©Ahmed Operating 187
Hagag Systems
Scheduling Algorithms
5. Multilevel Queue

Scheduling

Process Arrival
Waiting Time
Time
1 0
0
� �� ���� ���� ����
P
P2 1
� ��

1
P3 2 0 7−1 15 + 8 − 2
� P4 3 = � = �� = ����
� �
2 7ms 15ms 23ms 43m 59ms 83m

7m
s 31ms
8
s
m s
67ms s
��1 ��2 ��3 8��
8ms ms 4

16ms 12ms 16ms
0
� ��2 ��3 ��4

36ms 16ms
1
� ��2 ��4

2
©Ahmed Operating 188
Hagag Systems
Scheduling Algorithms
5. Multilevel Queue

Scheduling

Process Arrival
Waiting Time
Time
1 0
0
�� ���� ���� ����
� P
P2 1
� ��
P3 2 0 7−1 15 + 8 − 2 23 + 12 + 8 − 3
1
� P4 3 = � = �� = ���� = ����
� �
2 7ms 15ms 23ms 43m 59ms 83m

7m
s 31ms
8
s
m s
67ms s
��1 ��2 ��3 8��
8ms ms 4

16ms 12ms 16ms
0
� ��2 ��3 ��4

36ms 16ms
1
� ��2 ��4

2
©Ahmed Operating 189
Hagag Systems
Scheduling Algorithms
5. Multilevel Queue

Scheduling

Proces Arrival Time
Turnaround Time
s 0
0
��� ��� ��� ����
� P1 P 1
2
� � � �

1
P3 2
� P4 3

2 7ms 15ms 23ms 43m 59ms 83m

7m
s 31ms
8
s
m s
67ms s
��1 ��2 ��3 8��
8ms ms 4

16ms 12ms 16ms
0
� ��2 ��3 ��4

36ms 16ms
1
� ��2 ��4

2
©Ahmed Operating 190
Hagag Systems
Scheduling Algorithms
5. Multilevel Queue

Scheduling

Proces Arrival Time
Turnaround Time
s 0
0
���� ��� ��� ����
� P1 P 1
2
� � �

1
P3 2 7−0
� P4 3 = ��

2 7ms 15ms 23ms 43m 59ms 83m

7m
s 31ms
8
s
m s
67ms s
��1 ��2 ��3 8��
8ms ms 4

16ms 12ms 16ms
0
� ��2 ��3 ��4

36ms 16ms
1
� ��2 ��4

2
©Ahmed Operating 191
Hagag Systems
Scheduling Algorithms
5. Multilevel Queue

Scheduling

Proces Arrival Time
Turnaround Time
s 0
0
���� ���� ��� ����
� P1 P 1
2
� �

1
P3 2 7−0 67 − 1
� P4 3 = �� = ���
� �
2 7ms 15ms 23ms 43m 59ms 83m

7m
s 31ms
8
s
m s
67ms s
��1 ��2 ��3 8��
8ms ms 4

16ms 12ms 16ms
0
� ��2 ��3 ��4

36ms 16ms
1
� ��2 ��4

2
©Ahmed Operating 192
Hagag Systems
Scheduling Algorithms
5. Multilevel Queue

Scheduling

Proces Arrival Time
Turnaround Time
s 0
0
���� ���� ���� ����
� P1 P 1
2
� 7−0 67 − 1 43 − 2
1
P3 2
= �� = ��� = ����
� P4 3 �

2 7ms 15ms 23ms 43m 59ms 83m

7m
s 31ms
8
s
m s
67ms s
��1 ��2 ��3 8��
8ms ms 4

16ms 12ms 16ms
0
� ��2 ��3 ��4

36ms 16ms
1
� ��2 ��4

2
©Ahmed Operating 193
Hagag Systems
Scheduling Algorithms
5. Multilevel Queue

Scheduling

Proces Arrival Time
Turnaround Time
s 0
0
���� ���� ���� ����
� P1 P 1
2
� 7−0 67 − 1 43 − 2 83 − 3
1
P3 2
= �� = ��� = ���� = ����
� P4 3 �

2 7ms 15ms 23ms 43m 59ms 83m

7m
s 31ms
8
s
m s
67ms s
��1 ��2 ��3 8��
8ms ms 4

16ms 12ms 16ms
0
� ��2 ��3 ��4

36ms 16ms
1
� ��2 ��4

2
©Ahmed Operating 194
Hagag Systems
Scheduling Algorithms
5. Multilevel Queue

Scheduling

Proces Arrival Time
Response Time
s 0
0
��� ��� ��� ����
� P1 P 1
2
� � � �

1
P3 2
� P4 3

2 7ms 15ms 23ms 43m 59ms 83m

7m
s 31ms
8
s
m s
67ms s
��1 ��2 ��3 8��
8ms ms 4

16ms 12ms 16ms
0
� ��2 ��3 ��4

36ms 16ms
1
� ��2 ��4

2
©Ahmed Operating 195
Hagag Systems
5. Multilevel Queue
Scheduling Algorithms (24/3

Scheduling

Proces Arrival Time
Response Time
s 0
0
���� ��� ��� ����
� P1 P 1
2
� � �

1
P3 2 0−0
� P4 3 = ��

2 7ms 15ms 23ms 43m 59ms 83m

7m
s 31ms
8
s
m s
67ms s
��1 ��2 ��3 8��
8ms ms 4

16ms 12ms 16ms
0
� ��2 ��3 ��4

36ms 16ms
1
� ��2 ��4

2
©Ahmed Operating 196
Hagag Systems
Scheduling Algorithms
5. Multilevel Queue

Scheduling

Proces Arrival Time
Response Time
s 0
0
���� ���� ��� ����
� P1 P 1
2
� �

1
P3 2 0−0 7−1
� P4 3 = �� = ��

2 7ms 15ms 23ms 43m 59ms 83m

7m
s 31ms
8
s
m s
67ms s
��1 ��2 ��3 8��
8ms ms 4

16ms 12ms 16ms
0
� ��2 ��3 ��4

36ms 16ms
1
� ��2 ��4

2
©Ahmed Operating 197
Hagag Systems
Scheduling Algorithms
5. Multilevel Queue

Scheduling

Proces Arrival Time
Response Time
s 0
0
���� ���� ���� ����
� P1 P 1
2
� 0−0 7−1 15 − 2
1
P3 2
= �� = �� = ����
� P4 3

2 7ms 15ms 23ms 43m 59ms 83m

7m
s 31ms
8
s
m s
67ms s
��1 ��2 ��3 8��
8ms ms 4

16ms 12ms 16ms
0
� ��2 ��3 ��4

36ms 16ms
1
� ��2 ��4

2
©Ahmed Operating 198
Hagag Systems
Scheduling Algorithms
5. Multilevel Queue

Scheduling

Proces Arrival Time
Response Time
s 0
0
���� ���� ���� ����
� P1 P 1
2
� 0−0 7−1 15 − 2 23 − 3
1
P3 2
= �� = �� = ���� = ����
� P4 3

2 7ms 15ms 23ms 43m 59ms 83m

7m
s 31ms
8
s
m s
67ms s
��1 ��2 ��3 8��
8ms ms 4

16ms 12ms 16ms
0
� ��2 ��3 ��4

36ms 16ms
1
� ��2 ��4

2
©Ahmed Operating 199
Hagag Systems
Scheduling Algorithms
5. Multilevel Queue Scheduling
Now we add the concepts of varying arrival times and
preemption to the analysis
Process Arrival Time Burst
Time
P1 0 7
Using single-
P2 1 60
core processor
P3 2 20
P4 3 40

Multilevel Queue Fixed


priority
non-preemptive

©Ahmed Operating 200


Hagag Systems
Scheduling Algorithms

5. Multilevel Queue �
SchedulingProcess Arrival Time Burst 0

Time
1 �
P 0 7
1
P2 1 60 �
P3 2 20 �
P4 3 40 2


�0


�1

©Ahmed
� Operating 201
Hagag �2 Systems
Scheduling Algorithms

5. Multilevel Queue �
SchedulingProcess Arrival Time Burst 0

Time
1 �
P 0 7
1
P2 1 60 �
P3 2 20 �
2
P4 3 40

7
7m ms
s
� �
� �1

0
�1


©Ahmed � Operating 202
Hagag 2 Systems
Scheduling Algorithms

5. Multilevel Queue �
SchedulingProcess Arrival Time Burst 0

Time
1 �
P 0 7
1
P2 1 60 �
P3 2 20 �
2
P4 3 40

7
7m ms
s
� �
� �1

0
�1


©Ahmed � Operating 203
Hagag 2 Systems
Scheduling Algorithms
5. Multilevel Queue
SchedulingProcess Arrival Time Burst
Time
P1 0 7
P2 1 60 52
P3 2 20
P4 3 40
15m
s
7ms
� �� 7
8ms 1
ms


0 ��2
�1


©Ahmed � Operating 204
Hagag 2 Systems
Scheduling Algorithms
5. Multilevel Queue
SchedulingProcess Arrival Time Burst
Time
P1 0 7
P2 1 60 52
P3 2 20 12
P4 3 40
15ms
7ms 23m
7ms
� �� s
8ms 1 ��2
� ��

0 3

�1


©Ahmed � Operating 205
Hagag 2 Systems
Scheduling Algorithms
5. Multilevel Queue
SchedulingProces Arrival Time Burst
s Time 0 7
P1 P2 1 60
P3 P4 2
52
3
20
15ms 3
1ms 7ms 12
8 40
8 23ms
7
ms ms
� �� �� �
ms
1 2
� � �8� 32
ms

0 3 4

�1


©Ahmed � Operating 206
Hagag 2 Systems
Scheduling Algorithms
5. Multilevel Queue
SchedulingProces Arrival Time Burst
s Time 0 7
P1 P2 1 60 5
P3 P4 2 2 3
6
3
20 1
15ms 31ms 2
7ms 23m 47m 40 3
s
7ms 8ms s 2
� �� 8ms
�� �
� � 1 �8�
2
16ms
ms
� 3
0 4
��2


1

©Ahmed 2 Operating 207
Hagag Systems
Scheduling Algorithms
5. Multilevel Queue
SchedulingProces Arrival Time Burst
s Time 0 7
P1 P2 1 60 5
P3 P4 2 2 3
6
3
20 1
15ms 31ms 59ms 2
7ms 23m 47m 40 3
s
7ms 8ms s 2
� �� 8ms
�� �
� � 1 �8�
2
16ms 12ms
ms
� 3
0 4
��2 ��3


1

©Ahmed 2 Operating 208
Hagag Systems
Scheduling Algorithms
5. Multilevel Queue
SchedulingProces Arrival Time Burst
s Time 0 7
P1 P2 1 60 5
P3 P4 2 2 3
6
3
20 1
15ms 31ms 59ms 2
7ms 23m 47m 40 3
s
7ms 8ms s 2
� �� 8ms
�� �
� � 1 �8�
2
16ms 12ms
ms
� 3
0 4
��2 ��3


1

©Ahmed 2 Operating 209
Hagag Systems
Scheduling Algorithms
5. Multilevel Queue
SchedulingProces Arrival Time Burst
s Time 0 7
P1 P2 1 60 5
P3 P4 2 2 3
6
3
20 1
15ms 31ms 59ms 2
7ms 23m 47m 75 40
m 3
s
7ms 8ms s s 2 1
� �� 8ms
�� � 6
� � 1 �8�
2
16ms 12ms 16ms
ms
� 3
0 4
��2 ��3 ��4


1

©Ahmed 2 Operating 210
Hagag Systems
Scheduling Algorithms
5. Multilevel Queue
SchedulingProces Arrival Time Burst
s Time 0 7
P1 P2 1 60 5
P3 P4 2 2 3
6
3
20 1
15ms 31ms 59ms 2
7ms 23m 47m 75 40
m 3 111m
s
7ms 8ms s s 2 1 s
� �� 8ms
�� � 6
� � 1 �8�
2
16ms 12ms 16ms
ms
� 3
0 4
��2 ��3 ��4
� 36ms

1 ��2

©Ahmed 2 Operating 211
Hagag Systems
Scheduling Algorithms
5. Multilevel Queue
SchedulingProces Arrival Time Burst
s Time 0 7
P1 P2 1 60 5
P3 P4 2 2 3
6
3
20 1
15ms 31ms 59ms 2
7ms 23m 47m 75 40
m 3 111m
s
7ms 8ms s s 2 1 s
� �� 8ms
�� � 6
� � 1 �8�
2
16ms 12ms 16ms
ms
� 3
0 4
��2 ��3 ��4
� 36ms

1 ��2

©Ahmed 2 Operating 212
Hagag Systems
Scheduling Algorithms
5. Multilevel Queue
SchedulingProces Arrival Time Burst
s Time 0 7
P1 P2 1 60 5
P3 P4 2 2 3
6
3
20 1
15ms 31ms 59ms 2
7ms 23m 47m 75 40
m 3 111ms
s 8ms s s 2 1
� ��
7ms
8ms
�� � 6 127ms
� � 1 �8�
2
16ms 12ms 16ms
ms
� 3
0 4
��2 ��3 ��4
� 36ms 16ms

1 ��2 ��4

©Ahmed 2 Operating 213
Hagag Systems
Scheduling Algorithms
5. Multilevel Queue
SchedulingProces Arrival Time Burst
s Time 0 7
P1 P2 1 60 5
P3 P4 2 2 3
6
3
20 1
15ms 31ms 59ms 2
7ms 23m 47m 75 40
m 3 111ms
s 8ms s s 2 1
� ��
7ms
8ms
�� � 6 127ms
� � 1 �8�
2
16ms 12ms 16ms
ms
� 3
0 4
��2 ��3 ��4
� 36ms 16ms

1 ��2 ��4

©Ahmed 2 Operating 214
Hagag Systems
Scheduling Algorithms
Turnaround Time
5. Multilevel Queue ���� ���� ���� ����
SchedulingProces Arrival Time Burst 7−0 67 − 1 43 − 2 83 − 3
s Time 0 7 = �� = 66 = 41 = 80
P1 P2 1 60 5
P3 P4 2 2 3
6
3
20 1
15ms 31ms 59ms 2
7ms 23m 47m 75 40
m 3 111ms
s 8ms s s 2 1
� ��
7ms
8ms
�� � 6 127ms
� � 1 �8�
2
16ms 12ms 16ms
ms
� 3
0 4
��2 ��3 ��4
� 36ms 16ms

1 ��2 ��4

©Ahmed 2 Operating 215
Hagag Systems
Scheduling Algorithms
Waiting Time
5. Multilevel Queue ���� ���� ���� ����
SchedulingProces Arrival Time Burst 0 7-1 15+8-2 23+12+8- 3
s Time 0 7
P1 P2 1 60 5 =0 = 6 = 21 = 40

P3 P4 2 2 3
6
3
20 1
15ms 31ms 59ms 2
7ms 23m 47m 75 40
m 3 111ms
s 8ms s s 2 1
� ��
7ms
8ms
�� � 6 127ms
� � 1 �8�
2
16ms 12ms 16ms
ms
� 3
0 4
��2 ��3 ��4
� 36ms 16ms

1 ��2 ��4

©Ahmed 2 Operating 216
Hagag Systems
Scheduling Algorithms
Response Time
5. Multilevel Queue ���� ���� ���� ����
SchedulingProces Arrival Time Burst
s 7−0 7−1 15 − 2 23 − 3
Time 0 7
P1 P2 = �� =6 = 13 = ����
1 60 5 ��
P3 P4 2 2 3
6
3
20 1
15ms 31ms 59ms 2
7ms 23m 47m 75 40
m 3 111ms
s 8ms s s 2 1
� ��
7ms
8ms
�� � 6 127ms
� � 1 �8�
2
16ms 12ms 16ms
ms
� 3
0 4
��2 ��3 ��4
� 36ms 16ms

1 ��2 ��4

©Ahmed 2 Operating 217
Hagag Systems

You might also like