What is a scheduler?
A is a software that helps schedule the processes in an operating system. It helps to keep all computer resources busy and allows multiple users to share system resources effectively.
A process may leave the CPU for one the following reasons:
Scheduling Policy
decides when thread leaves and
which thread is selected to replace it
Scheduling Mechanism
determines how the process
manager carries out its duties
Scheduling Mechanism has 3 parts
What does a CPU scheduler do
Selects from among the processes in ready queue, and allocates a CPU core to one of them
CPU scheduling decisions may take place when a process:
For situations 1 and 4, there is no choice in terms of scheduling. A new process (if one exists in the ready queue) must be selected for execution.
The dispatcher
Responsible for the context switch of the current task to a new task.
Dispatch latenc
Time it takes for the dispatcher to stop one process and start another running
Preemptive and Nonpreemptive Scheduling
Ponpreemptive no choice (1 and 4)
Preemptive have a choice (2 and 3)
Register Overhead:
Each register must be saved and restored during a context switch to ensure that a process can resume execution exactly where it left off. This involves reading the current register values and storing them in a safe location (usually in the process’s control block in memory), then loading the next process’s saved register values back into the registers.
Context Switch Phases:
Switching Cost
Preemptive Scheduling and Race Conditions
Scheduling Algorithm Optimization Criteria
Scheduling Criteria
Service Time t(pi): amount of time a process needs to be in running state (allocated the CPU) before it is completed.
Wait time W(pi): total amount of time a process needed to wait in a non-running state from the moment it is ready until it is completed.
Response time R(pi): total amount of time from the moment the process is ready until it is considered for the first time by the CPU (allocated the CPU for the first time).
Turnaround time TAT(pi): the amount of time between the process first enters the ready state until the moment the process exits the running state for the last time (terminated)
First Come First Served (FCFS) Scheduling
FCFS is the simplest scheduling algorithm. There is a single rule; schedule the first process to arrive, and let it run to completion.
PCB
Process Control Block
IS FCFS a Preemptive or Nonpreemptive?
Nonpreemptive
Shortest Job Next (SJN)
Is a scheduling policy that selects for execution the waiting process with the smallest execution time
Shortest Job Next (SJN) Preemptive or Nonpreemptive?
It can be both a preemptive and non-preemptive algorithm.
Waiting Time equation
=Total waiting time- time process executed- Arrival time
Priority Scheduling
Scheduling algorithm that schedules processes according to the priority assigned to each of the processes. Higher priority processes are executed before lower priority processes.
What is Aging
Is a scheduling technique used to prevent starvation in operating systems. It involves gradually increasing the priority of processes that have been waiting for a long time.