×

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

Operating System Properties

The Properties of Operating System are: Batch processingMultitaskingMulti-programmingInteractivityReal-Time SystemDistributed Environmentspooling 1. Batch Processing In Batch Processing, the OS first gathers the data and programs together in a batch, then processing starts. The operating system...

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.

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.

Functions of Operating System

The functions of Operating System are: Process Management Memory Management File Management Device Management Secondary storage Management Security Coordination between other software and users Networking Job Accounting Error detecting aids 1. Process Management Process Management support operating system to create and delete...

3 minutes read.

Unix Operating System

Unix Operating System Unix Operating System is a multiuser, portable, time-sharing, and multitasking operating system that was developed in 1969. Unix operating system was developed by a group of AT &...

3 minutes read.

Kernel in OS

What is Kernel in OS? The kernel is the core component in the operating system. The job of the kernel is to handle the communication between the hardware and the software. ...

2 minutes read.

Linux Operating System

What is Linux? The Linux operating system is used on various devices, including cellphones, automobiles, supercomputers, household gadgets, personal computers, and business servers. You can find Linux on your phones, thermostats, vehicles,...

8 minutes read.

FCFS (First-Come-First-Serve) Disk Scheduling Algorithm

FCFS Disk Scheduling Algorithm FCFS (First-Come-First-Serve) is the easiest disk scheduling algorithm among all the scheduling algorithms. In the FCFS disk scheduling algorithm, each input/output request is served in the order...

4 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.

Banker’s Algorithm in Operating System

What is Banker’s Algorithm? Bankers algorithm is an algorithm which is used for deadlock avoidance and resource allocation. It was established by Edsger Dijkstra. The reason behind the name ‘banker’s algorithm’...

8 minutes read.

What is Deadlock in OS?

Deadlock in Operating System In an Operating System, a process uses various resources, and the resources are used in the following manner: Request the ResourceUse the ResourceRelease the Resource In the Operating System, Deadlock is a condition...

4 minutes read.

File in Operating System

What is File in Operating System?  A file is defined as a collection of the interrelated information that is stored in the secondary memory or the non-volatile memory such as optical...

4 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.

What is Thread and Types of Thread

What is Thread A thread means a lightweight process. Thread is the basic unit of CPU execution, which consists of thread ID, Program counter, set of registers to hold the information of current...

7 minutes read.

Advantages of UNIX Operating System

What is UNIX OS? UNIX is a family of multitasking, multiuser operating systems that are used on a wide variety of computer platforms. It was developed in the late 1960s and...

4 minutes read.

Semaphore in Operating System

What is Semaphore in Operating System Semaphore is defined as an integer variable which is used to solve the problem of the critical section in process synchronization. In semaphore, we use...

3 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.

Multitasking Operating Systems

An operating system is the fundamental piece of software that enables a computer system to function and execute a command as intended. The user interface, hardware, and every other piece...

7 minutes read.

Strategies for Handling Deadlock

Strategies for Handling Deadlock The Strategies for handling Deadlock are: Deadlock IgnoranceDeadlock PreventionDeadlock AvoidanceDeadlock Detection and Recovery Deadlock Ignorance Deadlock Ignorance is the most popular deadlock handling strategy. We can use this in the various operating systems for...

2 minutes read.

Difference between SCAN and FCFS Disk Scheduling Algorithm

SCAN / Elevator Algorithm A different form of disc scheduling method is the SCAN disc scheduling algorithm. We move the disc arm in a certain direction in this process (the direction...

3 minutes read.