Facebook Pixel

Process Scheduling in Operating Systems

Process scheduling refers to the activity performed by the operating system to decide which process should use the CPU at a given time. It involves removing the currently running process from the CPU and selecting another process based on a specific scheduling strategy.

This mechanism is a core feature of multiprogramming systems, where multiple processes are kept in memory at the same time and share the CPU through time-sharing.

Types of Scheduling

Process scheduling can be broadly divided into two categories:

  • Non-preemptive Scheduling: In this approach, once a process gets the CPU, it continues execution until it completes or moves to a waiting state. The CPU is not forcibly taken away.
  • Preemptive Scheduling: Here, the operating system assigns the CPU to a process only for a limited time. If needed, the OS can interrupt the process and allocate the CPU to another process, often based on priority.

Process Scheduling Queues

The operating system organizes processes using queues. Each process has a Process Control Block (PCB), and depending on its state, it is placed in a corresponding queue. Key queues include:

  • Job Queue: Contains all processes present in the system.
  • Ready Queue: Holds processes that are prepared to run and waiting for CPU time.
  • Device Queues: Contains processes waiting for I/O operations.

When a process changes its state, its PCB is moved from one queue to another.

Process Scheduling Queues

How processes move between various queues in the operating system

Two-State Process Model

In the simplest model, processes exist in two states:

  • Running: The process is currently executing on the CPU.
  • Not Running: The process is waiting in a queue until it gets CPU time.

When a running process is interrupted or completes execution, it leaves the CPU. The scheduler then selects another process from the queue to execute.

Schedulers in Operating Systems

Schedulers are components of the operating system responsible for selecting processes for execution. There are three main types:

  • Long-Term Scheduler: Also known as the job scheduler, it decides which processes are admitted into the system. It selects processes from the job pool and loads them into memory. Its goal is to maintain a good balance between CPU-bound and I/O-bound processes and control the number of processes in memory.
  • Short-Term Scheduler: Often called the CPU scheduler, it selects one process from the ready queue and assigns the CPU to it. This scheduler operates very frequently and must be fast, as it directly affects system performance.
  • Medium-Term Scheduler: This scheduler handles process swapping. It temporarily removes processes from memory and stores them in secondary storage to reduce system load. When required, these processes can be brought back into memory for execution.

Comparison of Schedulers

Scheduler TypePrimary FunctionSpeed
Long-Term SchedulerControls system load, selects processes for memorySlower
Short-Term SchedulerSelects next process for CPU executionFastest
Medium-Term SchedulerManages swapping, balances memory usageModerate

Context Switching

Context switching is the process of saving the state of a currently running process and restoring the state of another process so that execution can continue smoothly.

When the CPU switches from one process to another:

  • The current process state is saved in its PCB.
  • The next process state is loaded from its PCB.
  • Execution resumes from where it was previously stopped.
Context Switching Diagram

The mechanism of saving and loading process states during a context switch

Overhead of Context Switching

Context switching requires time and resources because the system must store and reload process information. This includes:

  • Program counter
  • CPU registers
  • Scheduling data
  • Memory-related information
  • I/O state
  • Accounting details

Since these operations consume CPU cycles, excessive context switching can reduce overall system performance.

Conclusion
Process scheduling is essential for efficient CPU utilization in multitasking systems. By selecting appropriate processes for execution and managing system resources effectively, the operating system ensures smooth and balanced performance. However, minimizing overhead such as context switching remains important for maintaining high efficiency.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.