This document discusses different types of scheduling algorithms used by operating systems to determine which process or processes will run on the CPU. It describes preemptive and non-preemptive scheduling, and provides examples of common scheduling algorithms like first-come, first-served (FCFS), shortest job first (SJF), round robin, and priority-based scheduling. Formulas for calculating turnaround time and waiting time are also presented.
What is scheduling?
One CPU with a number of processes. Only one process
can use the CPU at a time which process is going to be
execute that thing decide a by scheduler and it’s whole
thing is called scheduling.
Two types of scheduling:
1. Preemptive
2.Non- Preemptive
3.
Preemptive :
i. Inpreemptive scheduling, the currently running process may be
interrupted and move to the ready state by OS(forcefully).
ii. It selects a process and lets it run for a specific time duration,
called time quantum.
iii. If process is still running at the end of the time interval, it is
suspended and the scheduler selects another process to run.
4.
Non-Preemptive :
i. Innon-preemptive scheduling, the running process can only
lose the processor voluntarily by terminating or by requesting
and I/O. OR, once CPU given to a process it can not be
preempted until the process completes its CPU burst.
ii. It selects a process to run and then just lets it run until it
blocks or terminates.
5.
Types of scheduler
Long-term scheduler:
load a job in memory
Runs infrequently
Medium-term scheduler:
Select ready process to run on CPU
Should be fast
Short-term scheduler:
Reduce multiprogramming or memory consumption
6.
Process Scheduling
• “process”and “thread” used interchangeably
• Which process to run next
• Many processes in “ready” state
New Ready Running Exit
Waiting
First-Come First-Serve (FCFS)
One ready queue;
OS runs the process at head of the queue;
New processes come in at the end of the queue;
Running process does not give up the CPU until it terminates
or it performs IO.
10.
Shortest Job First(SJF)
Best approach to minimize waiting time.
Impossible to implement.
Processer should know in advance how much time process will take.
11.
SJF isoptimal – gives minimum average waiting time for a given set of processes.
Process Arrival Time Burst Time
P1 0 7
P2 2 4
P3 4 1
P4 5 4
SJF (non-preemptive):
0 7 8 12 16
12.
P1 P2 P3P2 P4 P1
Example of Preemptive SJF
Process Arrival Time Burst Time
P1 0 7
P2 2 4
P3 4 1
P4 5 4
SJF (preemptive)
0 2 4 5 7 11 16
13.
Round Robin Scheduling
Each process is provided a fix time to execute called quantum.
Once a process is executed for given time period. Process is preempted and
other process executes for given time period.
Context switching is used to save states of preempted processes.
15.
Priority Based Scheduling
Each process is assigned a priority. Process with highest priority is to be executed first and so on.
Processes with same priority are executed on first come first serve basis.
Priority can be decided based on memory requirements, time requirements or any other
resource requirement.