Operating System Tutorial

Operating System Tutorial Types of Operating System Evolution of Operating System Functions of Operating System Operating System Properties Operating System Services Components of Operating System Needs of the Operating System

Operating Systems

Linux Operating System Unix Operating System Ubuntu Operating System Chrome Operating Systems Fedora Operating System MAC Operating System MS Windows Operating System Solaris Operating System Cooperative Operating System CorelDRAW Operating System CentOS FreeBSD Operating Systems Batch Operating System MS-DOS Operating System Commercial Mobile Operating Systems


Difference Between Multi-programming and Multitasking Difference between C-LOOK and C-SCAN Difference between Rotational Latency and Disk Assess Time Trap vs Interrupt Difference between C-SCAN and SSTF Difference between SCAN and FCFS Difference between Seek Time and Disk Access Time Difference between SSTF and LOOK Difference between Process and Program in the Operating System Difference between Protection and Security in Operating System

How To

How to implement Monitors using Semaphores How to Install a Different Operating System on a PC


What is Kernel and Types of Kernel What is DOS Operating System What is Thread and Types of Thread What is Process Scheduler and Process Queue What is Context Switching What is CPU Scheduling What is Producer-Consumer Problem What is Semaphore in Operating System Monitors in Operating System What is Deadlock What is Paging and Segmentation What is Demand Paging What is Virtual Memory What is a Long term Scheduler What is Page Replacement in Operating System What is BSR Mode What is Convoy Effect What is Job Sequencing in Operating System Why is it critical for the Scheduler to distinguish between I/O-bound and CPU-bound programs Why is there a Need for an Operating System


Process Management Process State Scheduling Algorithm FCFS (First-come-First-Serve) Scheduling SJF (Shortest Job First) Scheduling Round-Robin CPU Scheduling Priority Based Scheduling HRRN (Highest Response Ratio Next) Scheduling Process Synchronization Lock Variable Mechanism TSL Mechanism Turn Variable Mechanism Interested Variable Mechanism Deadlock Avoidance Strategies for Handling Deadlock Deadlock Prevention Deadlock Detection and Recovery Resource Allocation Graph Banker’s Algorithm in Operating System Fixed Partitioning and Dynamic Partitioning Partitioning Algorithms Disk Scheduling Algorithms FCFS and SSTF Disk Scheduling Algorithm SCAN and C-SCAN Disk Scheduling Algorithm Look and C-Look Disk Scheduling Algorithm File in Operating System File Access Methods in Operating System File Allocation Method Directory Structure in Operating System N-Step-SCAN Disk Scheduling Feedback Queue in Operating System Contiguous Memory Allocation in Operating System Real-time Operating System Starvation in Operating System Thrashing in Operating System 5 Goals of Operating System Advantages of Operating System Advantages of UNIX Operating System Bit Vector in Operating System Booting Process in Operating System Can a Computer Run Without the Operating System Dining Philosophers Problem in Operating System Free Space Management in Operating System Inter Process Communication in Operating System Swapping in Operating System Memory Management in Operating System Multiprogramming Operating System Multitasking Operating Systems Multi-user Operating Systems Non-Contiguous Memory Allocation in Operating System Page Table in Operating System Process Scheduling in Operating System Segmentation in Operating System Simple Structure in Operating System Single-User Operating System Two Phase Locking Protocol Advantages and Disadvantages of Operating System Arithmetic operations in binary number system Assemblers in the operating system Bakery Algorithm in Operating System Benefits of Ubuntu Operating System CPU Scheduling Criteria in Operating System Critical Section in Operating System Device Management in Operating System Linux Scheduler in Operating System Long Term Scheduler in Operating System Mutex in Operating System Operating System Failure Peterson's Solution in Operating System Privileged and Non-Privileged Instructions in Operating System Swapping in Operating System Types of Operating System Zombie and Orphan Process in Operating System 62-bit operating system Advantages and Disadvantages of Batch Operating System Boot Block and Bad Block in Operating System Contiguous and Non - Contiguous Memory Allocation in Operating System Control and Distribution Systems in Operations Management Control Program in Operating System Convergent Technologies in Operating System Convoy Effect in Operating System Copy Operating Systems to SSD Core Components of Operating System Core of UNIX Operating System Correct Value to return to the Operating System Corrupted Operating System Cos is Smart Card Operating System Cosmos Operating Systems Examples Generation of Operating System Hardware Solution in Operating System Process Control Block in Operating System Function of Kernel in Operating System Operating System Layers History of Debian Operating Systems Branches and Architecture of Debian Operating Systems Features and Packages of Debian Operating Systems Installation of Operating System on a New PC Organizational Structure and Development in Debian Operating Systems User Interface in Operating System Types Of Memory in OS Operating System in Nokia Multilevel Paging in OS Memory Mapping Techniques in OS Memory Layout of a Process in Operating System Hardware Protection in Operating System Functions of File Management in Operating System Core of Linux Operating System Cache Replacement Policy in Operating System Cache Line and Cache Size in Operating System What is Memory Mapping? Difference Between Network Operating System And Distributed Operating System What is the difference between a Hard link and a Soft Link? Principles of Preemptive Scheduling Process Scheduling Algorithms What is NOS? What is the Interrupt I/O Process? What is Time Sharing OS What is process termination? What is Time-Sharing Operating System What is Batch File File system manipulation What is Message-passing Technique in OS Logical Clock in Distributed System

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.