Operating System IT-41033
Operating System IT-41033
IT-41033
CHAPTER – 5
My Profile
minnyithattant@gmail.com
minnyithattant
www.facebook.com/minnyithattant (မင််းညီသက်တ)ံ့
2
Semester - I
Overview
C-1 Introduction
C-2 System Structures
5.1 Basic Concept
5.2 Scheduling Criteria
Process Management 5.3 Scheduling Algorithms
C-3 Process Concept 5.4 Thread Scheduling
C-4 Multithreaded Programming 5.5 Multiple-Processor Scheduling
C-5 Process Scheduling 5.6 Operating System Examples
5.7 Algorithm Evaluation
5.8 Summary
Process Coordination
C- 6 Synchronization
C-7 Deadlocks
CHAPTER (5): PROCESS SCHEDULING
• Objectives
• To introduce CPU scheduling, which is the basis for multiprogrammed
operating system
• To describe various CPU-scheduling algorithms
• To discuss evaluation criteria for selecting a CPU-scheduling algorithm for a
particular system.
5.1 BASIC CONCEPT
• CPU Scheduling is central to operating system design.
• Process two states: CPU burst distribution, I/O burst cycle
• Keep several processes in memory.
• Every time one process has to wait, another process takes over the use of the CPU
• CPU-I/O burst cycle: Process execution => a cycle of CPU execution and I/O wait
(i.e., CPU burst and I/O burst).
• Large number of short CPU bursts, and a small number of long CPU bursts.
• An I/O-bound program would typically has many very short CPU bursts.
• A CPU-bound program might have a few long CPU bursts
Alternating sequence of CPU and I/O bursts
Example
Dispatcher
• Dispatcher module gives control of the CPU to the process selected by the short-term scheduler:
• switching context (restore the state of process to be run next)
• switching to user mode (for security and privilege break)
• jumping to the proper location in the user program (restart that program)
• Dispatch latency – time it takes for the dispatcher to stop one process and start another running
• When multiple tasks or programs want to use the CPU, the dispatcher helps decide which one gets to go
next.
5.2 SCHEDULING CRITERIA
(Non-preemptive) P2 P3 P1 P0
P0 16 16-3=13 13-2=11
P1 14 14-2=12 12-4=8
P2 6 6-0=6 6-6=0
P3 10 10-1=9 9-4=5
P4 = 6 P3 = 3 P2 = 2 P1 = 4
Shortest-Job-First Scheduling (SJF)
• Algorithm associates with each process the length of its next CPU burst.
• Use these lengths to schedule the process with the shortest time
• Algorithm can be either preemptive or nonpreemptive.
• A more appropriate term for this scheduling method: Shortest-next-CPU-Burst Algorithm
Shortest-Job-First Scheduling (SJF)
• SJF (non-preemptive)
Explanation:
Start 0, but 1ms, P2 arrive, so, P2 run, at that time
P2’s burst time is shortest, so, P2 executes. And, next
shortest is P4, it executes. Then, P1 and P3
• SJF
• Waiting time = Total waiting time – no. of ms process executed - Arrival time
• SJF (preemptive)
• Waiting time = Total waiting time – no. of ms process executed - Arrival time
P5 P2
• Design for time sharing system
• Similar to FCFS
P4 P3
• Preemptive is added to switch between process.
• CPU scheduler goes around the ready queue, allocating the CPU to each process for time
interval of up to 1 time quantum.
Round-Robin Scheduling Example
Burst 0 4 7 10 14 18 22 26 30
Process
Time P1 P2 P3 P1 P1 P1 P1 P1
P1 24
P2 3 • Turnaround time = Completion time – Arrival time
P3 3 • Waiting time = Turnaround time – Burst time
• Set of process: arrive at time 0, round robin with time quantum takes 4 ms
0 Highest priority
1 Medium priority
2 Low priority
5.4 THREAD SCHEDULING
PThreads Scheduling
Draw grant chart and find average waiting time using SJF preemptive.
Arrival Burst
Process
Time Time
P1 2 6
P2 5 2
P3 1 8
P4 0 3
P5 4 4
• Waiting time = Total waiting time – no. of ms process executed - Arrival time
References
Images: Internet
Source: Operating System Concepts (8th Edition)