After reading this tutorial you will find the answer and detail about
- What is Processing scheduling
- Types of Process scheduling algorithms
- Types of Schedulers in OS
- What is Context switching in os
To increase CPU utilization, multiple processes are loaded into the memory of the CPU and a process is selected from these processes. Loading multiple processes into the main memory is called multiprogramming. And, from these processes, a process is selected for execution. This selection is called scheduling. More than one process can also be executed simultaneously in the case of the multiprocessor system.
What is Process Scheduling in OS
Process scheduling is an essential part of operating system design, as it determines how the operating system assigns CPU time to processes. The goal of process scheduling is to achieve efficient utilization of the CPU, fast response time, and fair allocation of resources among all processes.
The process scheduling algorithm selects the next process to execute on the CPU from the ready queue. The ready queue contains a list of all the processes that are waiting for the CPU.
Different Types of Process Scheduling Algorithms in OS
There are several process scheduling algorithms that can be used to manage the ready queue:
- First-Come-First-Served (FCFS) scheduling: This is the simplest scheduling algorithm, where the process that arrives first is executed first. The ready queue is organized as a FIFO (First-In, First-Out) queue.
- Shortest Job First (SJF) scheduling: This algorithm selects the process with the shortest burst time (i.e., the time required to complete a process) from the ready queue. This algorithm is optimal in terms of minimizing average waiting time for processes, but it requires accurate estimates of burst times.
- Priority scheduling: This algorithm assigns a priority to each process based on its importance or urgency. Processes with higher priority are executed first, and processes with the same priority are executed in a FCFS order.
- Round-Robin scheduling: This algorithm allocates a fixed time slice to each process in the ready queue. When the time slice expires, the process is preempted, and the next process in the queue is executed.
- Multilevel queue scheduling: This algorithm partitions the ready queue into multiple levels, where each level represents a different type of process. Processes with higher priority are executed first, and processes with the same priority are executed in a FCFS order. Each level can have its own scheduling algorithm.
- Multilevel feedback queue scheduling: This algorithm is a variation of multilevel queue scheduling that allows processes to move between different priority levels based on their behavior. For example, if a process uses a lot of CPU time, it may be moved to a lower priority level to give other processes a chance to run.
The choice of process scheduling algorithm depends on the specific requirements of the system and the applications running on it. A good process scheduling algorithm should balance CPU utilization, response time, throughput, and fairness among processes.
Schedulers in OS
The selection of process from the main memory and execution is done in an orderly manner based on certain criteria. This selection is carried out by a scheduler.
Types of Schedulers in OS
There are several types of schedulers in an operating system (OS):
-
Long-term scheduler: This scheduler selects processes from the job pool and admits them into the system for processing. Its main objective is to maintain a good mix of CPU-bound and I/O bound processes to ensure that the CPU is utilized efficiently.
- Short-term scheduler: This scheduler selects a process from the ready queue and assigns it to the CPU for execution. Its main objective is to maximize CPU utilization and minimize the average waiting time for processes in the ready queue.
- Medium-term scheduler: Sometimes, it becomes necessary to remove some processes from the memory and later load the same program to the memory. This process is called swapping. And, removing the program from the memory is called swap out whereas again loading the program to memory is called swap in. This task is carried out by the medium-term scheduler.
- Batch scheduler: This scheduler is used to execute a large number of jobs that require similar resources, such as CPU time, memory, and I/O operations. It organizes the jobs into batches and schedules each batch for processing.
- Interactive scheduler: This scheduler is designed for interactive computing where the user requests immediate responses from the system. It gives priority to processes that generate user input/output requests and allocates resources to ensure that these processes respond quickly.
- Real-time scheduler: This scheduler is used in real-time systems where tasks need to be completed within a specific deadline. It allocates resources to processes that require them based on their priority and deadline.
-
Distributed scheduler: This scheduler is used in a distributed computing environment where tasks are distributed across multiple machines. It manages the allocation of resources to each task and monitors their progress to ensure that they are completed on time.
- Thread scheduler: This scheduler is responsible for managing the execution of threads within a process. It assigns threads to available CPU cores and determines their priority and order of execution.
- Deadline scheduler: This scheduler is used in real-time systems where tasks have a deadline to be completed. It schedules tasks based on their deadlines and priority to ensure that they are completed within the specified time frame.
- Round-robin scheduler: This scheduler is a preemptive scheduling algorithm that allocates a fixed time quantum to each process in the ready queue. It switches between processes once the time quantum expires, giving each process a fair share of the CPU’s time.
- Priority scheduler: This scheduler assigns priorities to processes based on their characteristics and assigns CPU time to higher-priority processes first. It ensures that processes with higher importance or urgency are completed first.
- Fair-share scheduler: This scheduler ensures that each user or group of users gets a fair share of the CPU’s time, regardless of the number of processes they have in the system.
The choice of scheduler depends on the specific requirements of the system and the applications running on it. A good scheduler should be able to balance CPU utilization, response time, throughput, and fairness among processes.
Context Switching
Sometimes in general-purpose systems, when an interrupt occurs the CPU need to switch to the kernel routines. When an interruption occurs, the current state of the process needs to be saved so that it can be resumed from there onwards later. This state is called context and it is saved in the PCB. This saving and resuming of the process is known as context switching. The time in context switching is called context switch time and it is an overhead for the system because at this time CPU does no useful work. The speed of context switching varies from hardware to hardware.
So, in this article, we learned about the different types of schedulers and context switching.