CPU Scheduling - TarisMajor/5143-OpSystems GitHub Wiki

CPU-Scheduling

CPU scheduling is a fundamental operating system function that manages the execution of processes by determining which process will utilize the CPU at any given time. Efficient CPU scheduling is crucial for maximizing CPU utilization, ensuring fair process execution, and achieving optimal system performance.

Key Characteristics of CPU Scheduling

  1. Process Management: The primary goal of CPU scheduling is to ensure that multiple processes can share the CPU efficiently without significant delays.
  2. Scheduler: The scheduling mechanism is implemented by a scheduler, which can be part of the operating system kernel.

Objectives of CPU Scheduling

  1. Maximize CPU Utilization: Ensure that the CPU is kept as busy as possible.
  2. Minimize Waiting Time: Reduce the time a process spends waiting in the ready queue.
  3. Minimize Turnaround Time: Reduce the total time taken for a process to complete execution.
  4. Maximize Throughput: Increase the number of processes completed per unit of time.
  5. Ensure Fairness: Ensure that all processes get a fair share of CPU time.

Common CPU Scheduling Algorithms

  1. First-Come, First-Served (FCFS)

    • Description: Processes are executed in the order they arrive in the ready queue.
    • Advantages: Simple to implement.
    • Disadvantages: Can lead to the "convoy effect," where short processes are delayed by long processes.
  2. Shortest Job Next (SJN)

    • Description: The process with the shortest expected execution time is selected next.
    • Advantages: Minimizes average waiting time.
    • Disadvantages: Requires knowledge of the execution time, which is not always feasible.
  3. Priority Scheduling

    • Description: Each process is assigned a priority, and the CPU is allocated to the process with the highest priority.
    • Advantages: Can provide better service to important processes.
    • Disadvantages: Can lead to starvation of low-priority processes.
  4. Round Robin (RR)

    • Description: Processes are executed for a fixed time slice (quantum) in a cyclic order.
    • Advantages: Fair and ensures that all processes get CPU time.
    • Disadvantages: The performance depends on the size of the time quantum.
  5. Multilevel Queue Scheduling

    • Description: Processes are divided into multiple queues based on priority, and each queue has its own scheduling algorithm.
    • Advantages: Flexible and can cater to different types of processes.
    • Disadvantages: Complex to implement and manage.
  6. Multilevel Feedback Queue Scheduling

    • Description: Similar to multilevel queue scheduling but allows processes to move between queues based on their behavior and requirements.
    • Advantages: Adaptable and can dynamically adjust to process behavior.
    • Disadvantages: Even more complex to implement and manage.

Sources for Further Reading