Process Scheduling / CPU Scheduling

  • Process scheduling is the OS mechanism that decides which processes run and in what order.

Goal: Ensure that the CPU is not idle and is always doing useful work.

Role of CPU Scheduler

  • Selects the next process to execute from the ready queue.
  • Uses a scheduling algorithm to choose the next process.

Aims of CPU Scheduling

  1. Ensure Fairness: Allocate CPU time fairly among all processes.
  2. Maximize CPU Utilization: Minimize idle time to keep CPU busy.
  3. Maximize Throughput: Increase the number of completed processes in a given period.
  4. Minimize Waiting Time: Reduce time processes spend in the ready queue.
  5. Minimize Response Time: Shorten the time between process submission and response.
  6. Minimize Turnaround Time: Decrease total time from process submission to completion.

Types of CPU Scheduling

  1. Preemptive Scheduling:
  • OS can interrupt and suspend a currently running process to start or resume another.
  1. Non-Preemptive Scheduling:
  • Once a process starts executing, it cannot be interrupted until it finishes or voluntarily yields the CPU.
AspectPreemptive SchedulingNon-Preemptive Scheduling
InterruptionYes, processes can be interruptedNo, once a process starts, it runs to completion
Context SwitchingFrequent, leading to overheadLess frequent, resulting in lower overhead
ComplexityMore complex to implementSimpler to implement
ResponsivenessHigh, suitable for real-time systemsLower, not suitable for real-time systems
Starvation RiskLower but possible with improper priority managementHigher, especially for low priority processes
Example AlgorithmsRound Robin, Priority Scheduling (Preemptive)First-Come First-Served (FCFS), Priority Scheduling (Non-Preemptive)

Important Keywords

  • โ€ข Burst Time: The amount of time a process requires the CPU between I/O waits.
  • Throughput: Number of processes completed per unit of time.
  • Turnaround Time: Total time from submission to completion of a process.
  • Waiting Time: Time a process spends waiting in the ready queue before it gets executed.

Pre-emptive Scheduling (Algorithms)

Round Robin Scheduling (RR)

  • The oldest, simplest, fairest and most widely used algorithm
  • Designed for time-sharing systems
  • A time quantum / time slice is defined for each process
  • The ready queue is treated as a circular queue
  • To implement round robin, the ready queue is kept as a first in first out queue
  • It tries to be fair by equally distributing the processing time among all theย processes
  • When the process uses up the time slice allocated to itself, it is put on the end of the ready list

Advantages:

  • Fair distribution of processing time.
  • Good response time for interactive processes.

Disadvantages:

  • If time slice is too short: Too many context switches โ†’ Lower CPU efficiency.
  • If time slice is too long: Poor response time for short tasks.

Next Lec 4 Memory Management>>>