Process scheduling organizes the processes to maximize CPU utilization. Process scheduling supports multiprogramming. Multiple processes are loaded to the main memory of the CPU and the processes are switched so frequently such that CPU is busy executing one process at a time while the other is in waiting state.
Process scheduling helps in determining which process should be allotted to CPU and which should be put on hold. It takes care that no process is starving and no process is engaging CPU for a long time keeping the other process on hold.
Concepts in Process Scheduling
Process Scheduling Queues
Every process in the main memory is organized in the queue which helps to classify which processes are ready for execution which are in waiting state. Whenever a process gets created it is placed in the job queue. The job queue is one where all the processes in system stay till the get ready for execution.
When a process is ready for execution it is brought to the main memory and placed in the ready queue. When a CPU gets free the first process in ready queue is allotted to CPU for execution.
When a process executing in CPU quits for the reasons like waiting for the occurrence of an event (I/O request to complete). Processes waiting for sharing of I/O devices are placed in the device queue.
Process scheduling would be easier to understand with a standard representation of queuing diagram. You can observe two scheduling queues in the diagram ready queue and device queue.
Resources serving the queues are represented with the circles whereas arrows represent how a process navigates in the system. Now let’s interrogate the diagram.
When a process enters main memory for execution it is placed in ready queue till CPU can be allotted to it or it is dispatched.
Now, once CPU is allotted to the process, there are a series of events that can occur to the process we will discuss them one by one.
- If a process requests for an I/O device then it would be placed in I/O queue or a device queue.
- In case the process had created a child process then it has to wait till child executes completely.
- In case the process is interrupted due to any reason it would be placed back in the ready queue.
Process Scheduling Classification
Scheduling can be classified into two kinds that are discussed below:
- Pre-emptive Scheduling: Pre-emptive scheduling of a process allows the system to pre-empt the process in between its execution and respond to another process.
- Non-Preemptive Scheduling: This kind of schedule does not allow the system to pre-empt the process in-between its execution.
Types of Scheduler
After the classification of process scheduling lets move on to the types of process scheduler. There are three types of scheduling as discussed below:
- Long Term Scheduler:
As we have seen above whenever a process is created it is placed in the job queue. Now, it is the task of long term schedular to determine which process from the job queue will be placed into the main memory.
Long term schedular is also known as job schedular as it adds the processes from job queue to main memory. Job scheduler has to perform less frequently as it at least requires a minute to create a new process.
- Short Term Scheduler:
Now, when the processes are in main memory waiting for CPU allocation, it is the task of short term schedular to select the process from main memory and assign CPU to it for its execution.
The medium-term schedular is also called CPU schedular as it allocates CPU to the processes ready for execution. Short term schedular has to perform frequently as it has to keep CPU busy.
- Medium Term Scheduler:
When the process is in execution it may be interrupted or it may wait for an event to occur. The suspended or waiting processes occupy memory space so they are swapped to the secondary memory and in the favourable condition, it is again placed in main memory.
This swapping of processes is conducted by the medium-term schedular.
As we know whenever the interrupt occurs the CPU has to suspend its current process and run the kernel routine and when its processing is complete it resumes the suspended process. This scenario is context switching.
When CPU suspend its current process it stores the context of the process in PCB. It stores information such as process current state, CPU registers values memory management information.
This information helps CPU identifying at what stage it has left the process when it resumes back the suspended process. Context switching creates overhead for the system as it is not performing any useful work at that moment. The switching speed varies from system to system depending on their memory speed.
So, in this article, we have studied process scheduling, its classification and its type. We have also covered the context switching concept in process scheduling.