Process Scheduling: Operating System

Process Scheduling: Operating System

7 mins read8.5K Views Comment
clickHere
Updated on Nov 29, 2023 15:43 IST

Have you ever wondered how your computer juggles multiple tasks simultaneously?  To know that, you must read this blog on process scheduling in the operating system!

When running a business, you need to ensure each department is running smoothly and that tasks are being completed efficiently. The same thing is expected in operating systems where different processes are going on, and the operating system is like the manager who takes care of everything. How does the Operating system manage all the processes? This is where process scheduling comes in. Process scheduling organises and monitors tasks to ensure they are completed on time by allocating resources to processes. There are many different types of schedulers, so it can be challenging to know which one is right for your business.

Functions of Operating System
Functions of Operating System
An operating system (OS) is software that manages computer software and hardware resources. Different operating systems have different app stores and could have different applications in them, too. This article...read more

Evolution of Operating System
Evolution of Operating System
In this article, we will discuss the history of operating systems, i.e., how operating systems are evolved over years. The journey that started from back in 1940 leveraging current digital...read more

In this post, we’ll explore the process of scheduling and different types of schedulers.

Table of Content

What is Process Scheduling?

Process scheduling is allocating resources to tasks so that the tasks can be completed in an efficient and timely manner.

There are a few different types of schedulers:

We will cover these operating systems in the next blog. Stay tuned!!!

Difference Between Multiprocessing and Multiprogramming
Difference Between Multiprocessing and Multiprogramming
The article covers the major difference between multiprocessing and multiprogramming in operating systems.

Difference Between Multiprogramming and Multitasking
Difference Between Multiprogramming and Multitasking
In this article we will explore the differences between Multiprogramming and Multitasking. This article also includes use cases of multiprogramming and multitasking.

Objectives of Process Scheduling

  • Optimize the use of resources present.
  • Keep the CPU busy and have maximum utilization of the CPU.
  • Minimum response time for executing a process means the shortest possible time for process execution.
Operating System Interview Questions
Operating System Interview Questions
In this article you will find important operating system questions which are likeable to be asked in interview.
Deadlock in Operating System
Deadlock in Operating System
A deadlock refers to a specific situation where two or more processes within the OS are unable to proceed because they are each waiting for a resource that the other...read more
Process Management in Operating System
Process Management in Operating System
Process management in operating systems involves the handling and coordinating multiple processes executed by the CPU. It includes tasks like process scheduling, creation, execution, and termination, ensuring efficient and fair...read more

Explore Operating System Online Courses & Certifications

Process Queues

There are multiple stages through which a process goes before its execution. A separate queue is maintained for all states.

These process scheduling queues are:

1. Job queue: All the processes stay here in this job before their execution. Now, processes are picked up and put in the READY queue.

2. Ready queue: The processes waiting to get executed are put in the READY queue. They remain here until they are picked up one by one for execution. 

3. Device queue: If the process is blocked during execution due to the unavailability of an I/O device, it goes to the Device queue. 

Types of Schedulers

A scheduler is a software that helps schedule the processes in an operating system. It helps to keep all computer resources busy and allows multiple users to share system resources effectively. Let’s go through different schedulers in an operating system.

1. Long-term schedulers

The processes that are created are in the NEW state. The programs are admitted to the RAM for execution. So before execution, the processes are put in the READY queue. So, do they get into the ready queue themselves? Here comes the role of long-term schedulers(LTS). It is also called a job scheduler. These schedulers select processes from secondary memory and put them into the ready queue.LTS runs less frequently. The main aim of LTS is to maintain the degree of multiprogramming. Multiprogramming means executing multiple programs by a single processor. But not all processes simultaneously. It means if one process is not executing for some reason, then another process will get a chance to get executed. An optimal level of multiprogramming means

The average rate of process = average departure rate of processes getting executed and leaving the system.

2. Short-term schedulers

It is also called a CPU scheduler. When the processes are in the ready queue, they are prepared to get executed. So the short-term schedulers select one process from the ready queue, put it in the running queue, and allocate a processor(CPU) to it. They are also known as the dispatcher who decides which process will execute next. They are faster than long-term schedulers. The performance of the system depends on the choice of Short-term schedulers. If it selects the processes having high burst time, then, in that case, other processes in the waiting queue will keep on waiting in the ready queue. This situation is called starvation. 

3. Medium-term schedulers

When the process is assigned CPU and the program execution starts, program execution is sometimes suspended. The reason could be an I/O request or some high-priority process. In this case, suspended processes cannot make any progress towards completion. So the process has to be removed from the memory and make space for other processes. The suspended process is moved back to the secondary storage. For example-Suppose, process 1 was executing, but it got suspended for some reason, so process 1 is swapped out, and process 2 is swapped in. This means swapping is taking place here. For doing swapping, we have a medium-term scheduler. 

Deadlock in Operating System
Deadlock in Operating System
A deadlock refers to a specific situation where two or more processes within the OS are unable to proceed because they are each waiting for a resource that the other...read more
Operating System Interview Questions
Operating System Interview Questions
In this article you will find important operating system questions which are likeable to be asked in interview.
Functions of Operating System
Functions of Operating System
An operating system (OS) is software that manages computer software and hardware resources. Different operating systems have different app stores and could have different applications in them, too. This article...read more

Comparison of OS Schedulers

S.No. Criteria Long-Term Scheduler(LTS)/job scheduler Short-Term Scheduler(STS)/ CPU scheduler Medium-Term Scheduler(MTS)/swapping scheduler
1. Type of process It chooses a combination of CPU-bound and I/O-bound processes. It chooses the process to be executed. It chooses the process which needs to be swapped in/out.
2. Speed  Have a slow speed than a short-term scheduler as different processes are to be selected. Fastest Speed as one process is selected at one time. It has speed is between the other two
3.  Frequency of execution It executes much less frequently. As its job is to load processes in the ready queue only.    The short-term scheduler executes more frequently, at least once every 100 milliseconds. Frequency is in between both
4. Degree of multi-programming It controls the number of processes in the memory means DOM(degree of multiprogramming) Ensures less DOM(degree of multiprogramming) It reduces DOM(degree of multiprogramming)
5. Working It selects a process from a pool of processes and loads it into the READY queue. Selects a process in the READY state and put it in the RUNNING state for execution If some interrupt comes, it swaps the process out and swaps the process back for execution.


 

CPU and I/O bound processes

While executing a process needs CPU and I/O devices both. There is a need to have a balanced mix of CPU and I/O bound.

1. CPU Bound Process

These processes execute at the speed of the computer processor or central processor unit and involve more CPU usage. For example, the processes involving complex calculations are CPU-bound processes.

Note-These processes involve I/O devices also, but CPU involvement is more.

2. I/O Bound Process

These processes are executed at the speed of the I/O subsystem and involve more usage of I/O devices than the CPU. I/O bound process spends a significant amount of time waiting for input or output from a peripheral device. For example- Reading/writing to a disk

Since these processes can’t proceed until the requested data is available, they can often be delayed by other processes that are running on the system. This can cause problems with CPU utilization and lead to overall system instability.

 To optimize system performance, it’s crucial to identify and allocate resources to I/O-bound processes. This can be done using a variety of schedules, such as the FCFS, SJF, and Round Robin schedulers.

Context Switching

Context switching is the process of temporarily taking control of a computer from its current task and then switching to a different task. This process allows users to perform different tasks on the computer simultaneously. It is one of the most important aspects of operating systems, as it will enable users to access various applications and files easily.
Context switching has advantages and disadvantages.

Advantages

  • Context switching allows users to quickly switch between tasks, which can be helpful when working on complex tasks.
  • Context switching can also be used to keep users updated on various events in the operating system.
  • It is so fast that it gives an illusion of execution of multiple processes at the same time.

Disadvantages

  • Context switching can be time-consuming and require users to learn new techniques.
  • CPU remains idle and does not do any useful work.

Conclusion 

This article covered process queues in the operating systems, types of schedulers, and their comparison. If you liked the article, please share it with your friends.

FAQs

What is a process control block (PCB)?

A process control block (PCB) is a data structure maintained by the operating system for each process. It contains information about the process, such as its process ID, program counter, CPU registers, memory allocation, file descriptors, scheduling information, and other relevant details needed for process management and context switching.

Can process scheduling algorithms be dynamically adjusted during runtime?

Yes, process scheduling algorithms can be dynamically adjusted during runtime based on changing system conditions or priorities. For example, the priority of a process can be adjusted dynamically based on its behavior or resource requirements.

What is the difference between preemptive and non-preemptive scheduling?

Preemptive scheduling allows the operating system to interrupt a running process and allocate the CPU to another process based on priority or time quantum. Non-preemptive scheduling, on the other hand, allows a process to continue running until it voluntarily releases the CPU. Preemptive scheduling provides better responsiveness and avoids blocking higher-priority processes for an extended period.

About the Author

This is a collection of insightful articles from domain experts in the fields of Cloud Computing, DevOps, AWS, Data Science, Machine Learning, AI, and Natural Language Processing. The range of topics caters to upski... Read Full Bio