Open In App

Process Schedulers in Operating System

Last Updated : 02 Jan, 2025
Comments
Improve
Suggest changes
Like Article
Like
Report

A process is the instance of a computer program in execution.

  • Scheduling is important in operating systems with multiprogramming as multiple processes might be eligible for running at a time.
  • One of the key responsibilities of an Operating System (OS) is to decide which programs will execute on the CPU.
  • Process Schedulers are fundamental components of operating systems responsible for deciding the order in which processes are executed by the CPU. In simpler terms, they manage how the CPU allocates its time among multiple tasks or processes that are competing for its attention.

What is Process Scheduling?

Process scheduling is the activity of the process manager that handles the removal of the running process from the CPU and the selection of another process based on a particular strategy. Throughout its lifetime, a process moves between various scheduling queues, such as the ready queue, waiting queue, or devices queue.

Process-Scheduler
Process scheduler

Categories of Scheduling

Scheduling falls into one of two categories:

  • Non-Preemptive: In this case, a process's resource cannot be taken before the process has finished running. When a running process finishes and transitions to a waiting state, resources are switched.
  • Preemptive: In this case, the OS can switch a process from running state to ready state. This switching happens because the CPU may give other processes priority and substitute the currently active process for the higher priority process.

Please refer Preemptive vs Non-Preemptive Scheduling for details.

Types of Process Schedulers

There are three types of process schedulers:

1. Long Term or Job Scheduler

Long Term Scheduler loads a process from disk to main memory for execution. The new process to the 'Ready State'.

  • It mainly moves processes from Job Queue to Ready Queue.
  • It controls the Degree of Multi-programming, i.e., the number of processes present in a ready state or in main memory at any point in time.
  • It is important that the long-term scheduler make a careful selection of both I/O and CPU-bound processes. I/O-bound tasks are which use much of their time in input and output operations while CPU-bound processes are which spend their time on the CPU. The job scheduler increases efficiency by maintaining a balance between the two.
  • In some systems, the long-term scheduler might not even exist. For example, in time-sharing systems like Microsoft Windows, there is usually no long-term scheduler. Instead, every new process is directly added to memory for the short-term scheduler to handle.
  • Slowest among the three (that is why called long term).

2. Short-Term or CPU Scheduler

CPU Scheduler is responsible for selecting one process from the ready state for running (or assigning CPU to it).

  • STS (Short Term Scheduler) must select a new process for the CPU frequently to avoid starvation.
  • The CPU scheduler uses different scheduling algorithms to balance the allocation of CPU time.
  • It picks a process from ready queue.
  • Its main objective is to make the best use of CPU.
  • It mainly calls dispatcher.
  • Fastest among the three (that is why called Short Term).

The dispatcher is responsible for loading the process selected by the Short-term scheduler on the CPU (Ready to Running State). Context switching is done by the dispatcher only. A dispatcher does the following work: 

  • Saving context (process control block) of previously running process if not finished.
  • Switching system mode to user mode.
  • Jumping to the proper location in the newly loaded program.

Time taken by dispatcher is called dispatch latency or process context switch time.

scheduling_queues
Short-Term Scheduler

3. Medium-Term Scheduler

Medium Term Scheduler (MTS) is responsible for moving a process from memory to disk (or swapping).

  • It reduces the degree of multiprogramming (Number of processes present in main memory).
  • A running process may become suspended if it makes an I/O request. A suspended processes cannot make any progress towards completion. In this condition, to remove the process from memory and make space for other processes, the suspended process is moved to the secondary storage. This process is called swapping, and the process is said to be swapped out or rolled out. Swapping may be necessary to improve the process mix (of CPU bound and IO bound)
  • When needed, it brings process back into memory and pick up right where it left off.
  • It is faster than long term and slower than short term.
mts
Medium-Term Scheduler

Some Other Schedulers

  • I/O Schedulers: I/O schedulers are in charge of managing the execution of I/O operations such as reading and writing to discs or networks. They can use various algorithms to determine the order in which I/O operations are executed, such as FCFS (First-Come, First-Served) or RR (Round Robin).
  • Real-Time Schedulers: In real-time systems, real-time schedulers ensure that critical tasks are completed within a specified time frame. They can prioritize and schedule tasks using various algorithms such as EDF (Earliest Deadline First) or RM (Rate Monotonic).

Comparison Among Scheduler

Long Term SchedulerShort Term SchedularMedium Term Scheduler
It is a job schedulerIt is a CPU schedulerIt is a process-swapping scheduler.
The slowest scheduler.Speed is the fastest among all of them.Speed lies in between both short and long-term schedulers.
It controls the degree of multiprogrammingIt gives less control over how much multiprogramming is done.It reduces the degree of multiprogramming.
It is barely present or nonexistent in the time-sharing system.It is a minimal time-sharing system.It is a component of systems for time sharing.
It can re-enter the process into memory, allowing for the continuation of execution.It selects those processes which are ready to executeIt can re-introduce the process into memory and execution can be continued.

Context Switching

In order for a process execution to be continued from the same point at a later time, context switching is a mechanism to store and restore the state or context of a CPU in the Process Control block. A context switcher makes it possible for multiple processes to share a single CPU using this method. A multitasking operating system must include context switching among its features.

The state of the currently running process is saved into the process control block when the scheduler switches the CPU from executing one process to another. The state used to set the computer, registers, etc. for the process that will run next is then loaded from its own PCB. After that, the second can start processing.

Context Switching
Context Switching

In order for a process execution to be continued from the same point at a later time, context switching is a mechanism to store and restore the state or context of a CPU in the Process Control block. A context switcher makes it possible for multiple processes to share a single CPU using this method. A multitasking operating system must include context switching among its features.

  • Program Counter
  • Scheduling information
  • The base and limit register value
  • Currently used register
  • Changed State
  • I/O State information
  • Accounting information

Read more: Context Switching in Operating System

Conclusion

Process schedulers are the essential parts of operating system that manage how the CPU handles multiple tasks or processes. They ensure that processes are executed efficiently, making the best use of CPU resources and maintaining system responsiveness. By choosing the right process to run at the right time, schedulers help optimize overall system performance, improve user experience, and ensure fair access to CPU resources among competing processes.


Next Article

Similar Reads