0% found this document useful (0 votes)
9 views17 pages

OS Lecture 3

The document covers the fundamental concepts of process scheduling in operating systems, including the significance of scheduling for multiprogramming and the various types of schedulers (long-term, short-term, medium-term). It details process scheduling queues, their management, and the implementation of different scheduling algorithms such as FCFS, SJN, and Round Robin. Additionally, it discusses the role of context switching and the importance of maintaining efficient process execution.
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)
9 views17 pages

OS Lecture 3

The document covers the fundamental concepts of process scheduling in operating systems, including the significance of scheduling for multiprogramming and the various types of schedulers (long-term, short-term, medium-term). It details process scheduling queues, their management, and the implementation of different scheduling algorithms such as FCFS, SJN, and Round Robin. Additionally, it discusses the role of context switching and the importance of maintaining efficient process execution.
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/ 17

OPERATING SYSTEM – PROCESS SCHEDULING

Learning Objectives

Understand the fundamental concepts of process


scheduling
Analyze different process scheduling queues and their role.
Compare and contrast different schedulers
 Implement and evaluate common scheduling algorithms
 Understand the concept and significance of context
switching

CS-301, Operating System - Spring 2025 - BS-CS, Semester 5


OPERATING SYSTEM – PROCESS SCHEDULING

Process Scheduling

Process Scheduling: The activity of the process manager


that:

 Removes the currently running process from the CPU


 Selects another process to run based on a specific
scheduling strategy

Significance of Process Scheduling: Essential for


Multiprogramming operating systems.

 Enables multiple processes to reside in memory


concurrently
 Allows CPU sharing among processes through time
multiplexing

CS-301, Operating System - Spring 2025 - BS-CS, Semester 5


OPERATING SYSTEM – PROCESS SCHEDULING

Categories of Scheduling
Non-preemptive:
Resources cannot be taken away from a process until it
completes execution.
Switching occurs when the running process terminates.

Preemptive:
Resources are allocated to a process for a fixed time.
Processes can be switched from running to ready, or
waiting to ready.
CPU may prioritize other processes, preempting the
current one.

CS-301, Operating System - Spring 2025 - BS-CS, Semester 5


OPERATING SYSTEM – PROCESS SCHEDULING

Process Scheduling Queues


The OS maintains separate queues for each process state
(e.g., ready, running, waiting).

PCBs of all processes in the same state are placed in the


corresponding queue.

When a process changes state, its PCB is:


• Unlinked from its current queue
• Moved to the queue associated with its new state.

CS-301, Operating System - Spring 2025 - BS-CS, Semester 5


OPERATING SYSTEM – PROCESS SCHEDULING

Process Scheduling Queues


The OS maintains the following important process
scheduling queues:

 Job Queue - This queue keeps all the processes in the


system.

 Ready Queue - This queue keeps a set of all processes


residing in main memory, ready and waiting to execute. A
new process is always put in this queue.

 Device queues − The processes which are blocked due to


unavailability of an I/O device constitute this queue.

CS-301, Operating System - Spring 2025 - BS-CS, Semester 5


OPERATING SYSTEM – PROCESS SCHEDULING

Process Scheduling Queues


The OS can use different policies to manage each queue (FIFO,
Round Robin, Priority, etc.). The OS scheduler determines how to
move processes between the ready and run queues which can only
have one entry per processor core on the system; in the below
diagram, it has been merged with the CPU.

CS-301, Operating System - Spring 2025 - BS-CS, Semester 5


OPERATING SYSTEM – PROCESS SCHEDULING

Two-State Process Model


Two-state process model refers to running and non-running
states :

(1) Running: When a new process is created, it enters into the


system as in the running state

(2) Not Running: Processes that are not running are kept in
queue, waiting for their turn to execute.
Contd….

CS-301, Operating System - Spring 2025 - BS-CS, Semester 5


OPERATING SYSTEM – PROCESS SCHEDULING
Two-State Process Model

….. Contd.
Process Queue Implementation:
 Each queue entry is a pointer to a specific process.
 Queues are typically implemented using linked lists.

Dispatcher Role:
 When a process is interrupted:
It is transferred to the waiting queue.
 If a process completes or aborts:
It is discarded from the queue.
 The dispatcher then selects a process from the ready queue for
execution.

CS-301, Operating System - Spring 2025 - BS-CS, Semester 5


OPERATING SYSTEM – PROCESS SCHEDULING

Schedulers

 Special system software responsible for process


scheduling.

 Select jobs for system submission and decide which


process to run.

Types of Schedulers:
(1) Long-Term Scheduler

(2) Short-Term Scheduler

(3) Medium-Term Scheduler

CS-301, Operating System - Spring 2025 - BS-CS, Semester 5


OPERATING SYSTEM – PROCESS SCHEDULING

(1)Long-Term Scheduler (Job Scheduler):


• Determines which programs are admitted into the
system.
• Selects processes from the queue and loads them into
memory for execution.
Objectives:
• Provide a balanced mix of I/O-bound and processor-
bound jobs.
• Control the degree of multiprogramming.
Stable multiprogramming: Process creation rate =
Process departure rate.
Note:
• May not be present or minimal in some systems.
• Not typically found in time-sharing operating systems.
• Activated when a process transitions from the "new" to
"ready" state.

CS-301, Operating System - Spring 2025 - BS-CS, Semester 5


OPERATING SYSTEM – PROCESS SCHEDULING

(2) Short-Term Scheduler (CPU Scheduler):


• Selects the next process to execute from the ready queue.
• Allocates CPU to the chosen process.

Objectives:
• Increase system performance based on chosen criteria (e.g.,
throughput, turnaround time).

Characteristics:
• Also known as a dispatcher.
• Operates much faster than the long-term scheduler.

CS-301, Operating System - Spring 2025 - BS-CS, Semester 5


OPERATING SYSTEM – PROCESS SCHEDULING

(3) Medium-Term Scheduling:


• Involves swapping processes out of memory.
• Reduces the degree of multiprogramming.
• Manages swapped-out processes.
Swapping:
• Removes suspended processes (e.g., waiting for
I/O) from memory.
• Moves suspended processes to secondary storage.
• Creates space for other processes.
Purpose of Swapping:
• Improve the process mix in memory.

CS-301, Operating System - Spring 2025 - BS-CS, Semester 5


OPERATING SYSTEM – PROCESS SCHEDULING
Comparison among Scheduler

Short-Term Medium-Term
Long-Term Scheduler
Scheduler Scheduler
It is a process swapping
1 It is a job scheduler It is a CPU scheduler
scheduler.
Speed is in between both
Speed is lesser than short Speed is fastest
2 short and long term
term scheduler among other two
scheduler.
It provides lesser
It controls the degree of It reduces the degree of
3 control over degree of
multiprogramming multiprogramming.
multiprogramming
It is almost absent or
It is also minimal in It is a part of Time sharing
4 minimal in time sharing
time sharing system systems.
system
It selects processes from It selects those It can re-introduce the
pool and loads them into processes which are process into memory and
5 ready to execute execution can be continued.
memory for execution

CS-301, Operating System - Spring 2025 - BS-CS, Semester 5


OPERATING SYSTEM – PROCESS SCHEDULING
Scheduling Algorithms
A Process Scheduler schedules different processes to be
assigned to the CPU based on particular scheduling
algorithms.

Six (6) popular process scheduling algorithms:

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


(2) Shortest-Job-Next (SJN) Scheduling
(3) Priority Scheduling
(4) Shortest Remaining Time
(5) Round Robin(RR) Scheduling
(6) Multiple-Level Queues Scheduling

CS-301, Operating System - Spring 2025 - BS-CS, Semester 5


OPERATING SYSTEM – PROCESS SCHEDULING
(1) First-Come, First-Served (FCFS) Scheduling

• Jobs are executed on first come, first serve basis.


• It is a non-preemptive, pre-emptive scheduling
algorithm.
• Easy to understand and implement.
• Its implementation is based on FIFO queue.
• Poor in performance as average wait time is high.

https://www.youtube.com/watch?v=976ouzywr5E
Play the video for FCFS Scheduling example problem

CS-301, Operating System - Spring 2025 - BS-CS, Semester 5


OPERATING SYSTEM – PROCESS SCHEDULING
(1) First-Come, First-Served (FCFS) Scheduling

CS-301, Operating System - Spring 2025 - BS-CS, Semester 5


OPERATING SYSTEM – PROCESS SCHEDULING
(1) First-Come, First-Served (FCFS) Scheduling

Waiting time of each process is as follows −

Process Waiting Time : Service Time - Arrival Time


P0 0-0=0
P1 5-1=4
P2 8-2=6
P3 16 - 3 = 13

Contd…..

CS-301, Operating System - Spring 2025 - BS-CS, Semester 5

You might also like