CPU scheduling in operating system is a mechanism to move a process from state to queue and vice-versa. CPU scheduling allows one process to use the CPU while another process is doing I/O work. The objective of CPU scheduling is to make the system efficient and fast.
CPU scheduling decisions may take place when a process:
– Switches from running to ready state
– Switches from running to waiting state
– Switches from waiting to ready
– Terminates
Types of CPU Scheduling
There are two types of scheduling –
(1) Non Preemptive
(2) Preemptive
Non Preemptive CPU Scheduling
In Non Preemptive scheduling, a running process can’t be interrupted by any other process. Any other process which wants to enter the queue has to wait until the existing process finishes its CPU cycle.
If the process has the smallest burst time, it has to starve because CPU is allocated to a process with the largest burst time.
– Non preemptive scheduling is rigid. Examples: FCFS, SJF etc.
Preemptive CPU Scheduling
In preemptive scheduling, a running process can be interrupted if a high priority process request to CPU. Current process switches from running queue to ready queue.
If the process is of low priority, it has to starve for CPU resources because in preemptive scheduling high priority process can be interrupted at any time.
– The preemptive scheduling is flexible as it allows any high priority process.
– CPU Utilization is more compared to non-preemptive scheduling.
Examples: SRTF, Priority, Round Robin etc.
Objectives of CPU scheduling
Below are the criteria to check which scheduling is more flexible: –
Maximum CPU utilization
To make the CPU busy most of the time. CPU should not be idle.
Maximum throughput
Number of processes that complete the execution per unit time.
Minimum Turn Around Time
It is the amount of time taken by a process to finish execution.
Minimum waiting time
Time spent waiting in the ready queue.
Response time
Time when a process produces first response.
Formulas to be used in CPU Scheduling
We will use some formulas to calculate the Turn Around time, Waiting time and Completion time.
Formulas:
(1) Turn Around Time = Completion Time – Arrival Time
(2) Waiting Time = Turn Around Time – Burst Time
Algorithms of CPU Scheduling in Operating System
Below are the list of different algorithms of CPU Scheduling in operating system –
(1) First Come First Serve (FCFS) scheduling
(2) Shortest Job First (SJF) scheduling
(3) Priority Scheduling
(4) Round Robin Scheduling
(5) Multilevel queue scheduling
(6) Multilevel feedback queue scheduling
Here, we have seen introduction to cpu scheduling in operating system. In next chapter, we will go through every scheduling algorithm.