×

Process Scheduling in Operating System

Process Scheduling is an essential component of a Multiprogramming Operating System. So now let’s understand how it works by taking a real-life example. Suppose that you want to call someone from a PCO booth and someone is already on the phone, so you will wait for him/her to finish their phone call outside the booth making a queue and if there is a third person he will wait beside you in the line for his turn. What happened here is that all three of you made a schedule for using the PCO Booth and the guy who came first will use the phone first (First Come First Serve). The same thing happens in Operating System as the number of processes is more than resources and we have only one processor available to do the task whereas tasks are more than one. All the processes need the processor at the same time. Humans are sensible enough to organize and schedule themselves one after another but computers need the operating system to do that. The operating system takes responsibility and schedules these processes using the scheduling algorithms.

The operating system makes a queue of the processes in the main memory which needs the processor and it makes another queue when the memory is filled with enough processes.

There are a total of three types of queues which are given as follows:

  1. Job Queue: A place where the process waits to get the resources in the secondary memory is known as a job queue.
  2. Ready Queue: A place where the process waits to get the resources in the main memory is known as a ready queue.
  3. Waiting queue: If the process is waiting for some kind of input/output operations then it will wait in the waiting queue. The waiting queue is also present in the secondary memory.
Process Scheduling in Operating System

Process in the job queue will be transferred into the ready queue as soon as the tasks are completed in the ready queue.

Role of a Scheduling Algorithm

The scheduling algorithm plays a major role in making a sequence of processes in the queue. We cannot rely on First Come First Serve in the case of processing the tasks as some processes are urgent and some have more priority than others. This is where scheduling algorithms come into play which finds the process that came late but have priority over others to make them come first in the line.

Scheduling Algorithms have the following tasks to complete in the operating system:

  1. It arranges the processes in a queue.
  2. It assigns the process to the processor as soon as it gets free.
  3. Some processes get stuck in the processor and they don’t let the other processes get to the processor and the queue length starts increasing. In that case, the scheduling algorithm swaps in/swaps out those processes from the processor and replace them with another process.

Responsibilities of Scheduling Algorithm in OS

You might think that process gets processor automatically as whoever comes first will get processed first.  In our perspective, it does happen but the operating system does the whole work here for us. Processes wait in the different queues (Job queue, ready queue, and waiting queue) before they get processed and this is the responsibility of the algorithm to pick the process and assign it to the processor.

First thing, whenever we say things are getting done automatically in the world of computers, there is always some algorithm working behind it. To understand the duty of these algorithms let’s take a real-life example, Suppose there is a huge queue of vehicles on the road due to a traffic jam and you are a traffic policeman who has the authority and power to make changes to the queue. So, obviously you will give more priority to an ambulance to go first in the queue, the same thing does the operating system with the help of scheduling algorithms. Scheduling algorithms are the traffic policeman here which can make changes to the queue and are able to put any process in the forward direction according to their priority. Many times it happens that an urgent task is needed to be completed first in the processor and it is the responsibility of scheduling algorithms to help them in this condition. There can be a lot of different cases for which a process may demand the processor on a priority basis.

Types of Scheduling Algorithm

As we know that we have three different queues, Job, Ready, and Waiting queue. Similarly, we have three different Scheduling Algorithms given as follows:

  1. Long Term Scheduler
  2. Short Term Scheduler
  3. Mid Term Scheduler

Long Term Scheduler

The Long Term Scheduling algorithm is responsible for managing the process in the job queue which is present in the second memory and then transferring it to the ready queue. It checks which processes are a top priority and place it accordingly in the queue. Whenever a new process comes into the secondary memory and let’s say 7 processes are already in the queue then it will check its priority. Let’s say it finds out its priority is well suited for the third position then it will place the new process on the third position in the secondary memory. When the processor gets free, it places the processes from secondary memory to the main memory.

Short Term Scheduler

The Short Term Scheduling algorithm is responsible for managing the process in the ready queue which is present in the main memory. The processor gets the processes directly from the main memory as it is nearest to it and the Short Term Scheduler is responsible for that. It gets the processor from the job queue and then checks the priority of the processes and puts them into the ready queue accordingly. Later on, it assigns the processes present in the ready queue to the processor. The processor executes the processor provided by the Short-Term Scheduler one by one and the process will end. In case any process needs more input from the user or has some pending operations left then the CPU will place them in the I/O waiting queue where it will wait till it gets the required input from the user then it will be placed again in the ready queue. It will go on in a loop until the process comes to an end.

Mid Term Scheduler

You might think that it must be responsible for managing the process in the waiting queue. No, processes pass through different states in which when the process is waiting for some I/O operations before it gets processed, it gets placed in the waiting queue and it will go back to the ready queue once it gets the required Input/Output result. So again Short Term Scheduler will work over it not the Mid Term Scheduler.

So what exactly does the Mid Term Scheduling algorithm do? The Mid Term Scheduling algorithm is responsible to maintain a smooth flow and look for any obstacles faced by the processes on their way to the processor. Now the question arises what obstacles come in the way of process?  Sometimes, A process comes into the main memory (ready queue) and then keeps the memory reserve without getting processed by the processor which keeps the processor busy and other process gets stuck in the queue. The Mid Term Scheduler swaps out these processes from the main memory back to the secondary memory. It plays an important role in the system because sometimes a process of high priority needed to be executed first but the main memory is reserved by some less-priority process. The Mid Term Scheduler algorithm swipe in the process with high priority placing it in the main memory and swaps out the process with less priority from the main memory, basically we can say that it makes space for the high-priority process in the main memory. These swapped-out processes are partially executed already and it gets swapped in the ready queue back very shortly. It does the same thing again when it gets the processor back for execution then the same thing will go back in a loop until the process gets executed and the process comes to an end. Mid Term Scheduler is very important for our operating system as it manages the processes and helps the processor to be more efficient and give a good performance to the user.


Related Topics

Interested Variable Mechanism

Interested Variable Mechanism It is a must to provide progress to the process synchronization mechanism. In variable mechanism, if there is a process that doesn’t need to enter into the critical section, then due...

5 minutes read.

Difference between Multi-programming and Multitasking

Difference between Multiprogramming and Multitasking         Multiprogramming  Multitasking In Multiprogramming, at the same time, we can run the multiple processes concurrently on one...

2 minutes read.

Simple Structure in Operating System

An operating system is a piece of software that lets the user applications talk to the hardware of the system. Because it is such a complicated structure, the operating system...

3 minutes read.

Difference between C-LOOK and C-SCAN Disk Scheduling Algorithm

Disk scheduling is used by operating systems to arrange the arrival of I/O requests to the disc. I/O scheduling is another name for disc scheduling. Disk scheduling is necessary because...

4 minutes read.

Producer-Consumer Problem in OS

What is Producer-Consumer Problem? The Producer-Consumer problem is a classical problem. The Producer-Consumer problem is used for multi-process synchronization, which means synchronization between more than one processes. In this problem, we have one producer...

4 minutes read.

Partitioning Algorithms

Partitioning Algorithms There are various types of Partitioning Algorithm: First-Fit AlgorithmNext-Fit AlgorithmBest-Fit AlgorithmWorst-Fit AlgorithmQuick-Fit Algorithm 1. First-Fit Algorithm: - In the First-Fit Partitioning algorithm, first, the linked list is scan, and when it...

3 minutes read.

Virtual Memory in Operating System

What is Virtual Memory Virtual Memory is a storage scheme in which the users have an illusion that users have a significant amount of Main Memory. We can perform this by taking a...

3 minutes read.

Android Operating System

What is Android Operating System? Android is a Linux-based and open-source operating system mainly established for mobile devices like tablet computers and Smartphones. The Android operating system was established by the...

5 minutes read.

FCFS Scheduling in OS

FCFS: First Come First Serve Scheduling in OS FCFS is a non-preemptive and preemptive scheduling algorithm that is easy to understand and use. In this, the process which reaches first is...

3 minutes read.

MS-DOS Operating System

It is also referred to occasionally as "DOS", an abbreviation for disc operating systems. Operating systems with a graphical user interface (GUI) in different iterations of the graphical Microsoft Windows...

5 minutes read.

Components of Operating System

Components of Operating System: An operating system is a complex and vast system. We can only create the operating system by dividing it into small parts. Each part must be...

5 minutes read.

DOS Operating System

What is DOS Operating System? An operating system that runs from a hard disk drive is known as the DOS (Disk Operating System).In other words, DOS (Disk Operating System) is defined...

7 minutes read.

Look Disk Scheduling

Look Disk Scheduling Look disk scheduling is another type of disk scheduling algorithm. Look scheduling is an enhanced version of SCAN disk scheduling. Look disk scheduling is the same as SCAN disk scheduling,...

4 minutes read.

HRRN Scheduling in OS

Highest Response Ratio Next (HRRN) Scheduling in OS Highest Response Ratio Next Scheduling is a Non-Preemptive Scheduling algorithm. This algorithm provides the benefits of the shortest job first scheduling algorithm and also removes...

6 minutes read.

Deadlock Avoidance

Deadlock Avoidance In an operating system, for deadlock avoidance, we perform the following: We only grant the request of the resources if the resulting state of the system will not cause any deadlock in the...

3 minutes read.

How to implement Monitors using Semaphores

Monitors Monitor is a type of synchronization device designed to solve difficulties caused by semaphores, such as timing errors. Monitors are the type of data types that are abstract by nature...

2 minutes read.

Advantages of Operating System

What is an Operating System?   An operating system is an interface that helps to communicate with the user and the computer hardware. Operating systems are used for file management, memory...

3 minutes read.

Bit Vector in Operating System

What is Bit vector? Bit vector is one of the most important methods used in the free space management of operating system. Free space management which is used by the operating...

3 minutes read.

Distributed Shared Memory

Distributed Shared Memory is a process of managing memory over more than one node and makes inter-process communication which transfers to end users. It is a mechanism that allows user...

2 minutes read.

Monitors in Operating System

Monitors in Operating System Monitors are used for process synchronization. With the help of programming languages, we can use a monitor to achieve mutual exclusion among the processes. Example of monitors:...

3 minutes read.