All Exams Test series for 1 year @ ₹349 only
Question

In which of the following scheduling criteria, context switching will never take place?

The correct answer is

Non-preemptive SJF

Understanding CPU Scheduling and Context Switching

CPU scheduling is the process by which the operating system decides which process gets to use the CPU next. When the operating system switches the CPU from one process to another, this action is called a context switch.

A context switch involves saving the state of the current process (its context) so that it can be restored later, and then loading the saved state of the next process. This is a fundamental operation in multitasking operating systems and incurs some overhead.

CPU scheduling algorithms can be broadly classified into two types based on whether they allow preemption:

  • Preemptive Scheduling: The CPU can be taken away from a process before it completes its CPU burst. This often happens when a higher-priority process arrives, or a time slice expires (as in Round Robin). Preemption inherently involves a context switch.
  • Non-preemptive Scheduling: Once a process is allocated the CPU, it runs until it completes its CPU burst or voluntarily releases the CPU (e.g., by waiting for I/O). The CPU is not taken away from it by the scheduler due to the arrival of other processes.

Analyzing Scheduling Criteria and Context Switching

Let's look at the given options and how they relate to context switching:

  • ROUND ROBIN: This is a preemptive scheduling algorithm. Processes are given a fixed time slice (quantum). If a process does not complete within its time slice, it is preempted and moved to the ready queue. A context switch occurs when the CPU moves from the preempted process to the next process in the ready queue. Context switching happens frequently.
  • Preemptive SJF (Shortest Job First): This is a preemptive algorithm. If a new process arrives with a CPU burst time shorter than the remaining time of the currently executing process, the currently executing process is preempted. A context switch occurs to switch to the new, shorter process.
  • Non-preemptive SJF: This is a non-preemptive algorithm. When a process is selected to run, it runs until it completes its CPU burst or blocks for I/O. It is not preempted by the arrival of shorter jobs. A context switch only occurs when the currently running process finishes and the scheduler needs to pick the next process, or when it blocks. The key here is that a running process is never interrupted by the scheduler *because* a new job arrives that might be a better fit. It runs to completion of its burst.
  • Preemptive priority: This is a preemptive algorithm. If a new process arrives with a higher priority than the currently executing process, the currently executing process is preempted. A context switch occurs to switch to the higher-priority process.

The question asks in which criteria context switching will never take place. This phrasing is strong; a switch always takes place when the CPU is given to a different process. However, in the context of scheduling algorithms, it usually implies which algorithm avoids triggering a context switch *due to preemption* before a process finishes its current CPU burst. Among the given options, Non-preemptive SJF is the only one where a running process is guaranteed to complete its CPU burst without being interrupted by the scheduler simply because another process (like a shorter or higher priority one) becomes ready.

Therefore, while context switching still happens when a process finishes or blocks, Non-preemptive SJF is the algorithm among the choices that does not *force* a context switch due to preemption of a running process based on the scheduling criteria (like time slice expiration, or arrival of a shorter/higher-priority job).

Comparison of Scheduling Algorithms and Context Switching
Scheduling Algorithm Preemptive? Context Switching Triggered By...
ROUND ROBIN Yes Time slice expiration, Process completion, Blocking
Preemptive SJF Yes Arrival of shorter job, Process completion, Blocking
Non-preemptive SJF No Process completion, Blocking
Preemptive priority Yes Arrival of higher priority job, Process completion, Blocking

Based on this analysis, Non-preemptive SJF minimizes the triggers for context switching compared to the other options, specifically by eliminating preemption as a cause for switching away from a running process before its burst is complete.

Revision Table: CPU Scheduling Concepts

Term Definition Relevance to Context Switching
CPU Scheduling Method to choose which process gets the CPU from the ready queue. The algorithm determines when and why a context switch might occur.
Context Switching Saving the state of one process and loading the state of another. Happens whenever the CPU switches from one process to another. Incurs overhead.
Preemption Interrupting a running process before its CPU burst is complete. A direct cause of context switching in preemptive algorithms.
Non-preemption A process runs until completion or blocking once started. Avoids context switching triggered by external events like arrival of other jobs.

Additional Information on Scheduling Algorithms

Understanding different scheduling algorithms is crucial for grasping operating system concepts. Each algorithm has pros and cons regarding metrics like CPU utilization, throughput, turnaround time, waiting time, and response time.

  • SJF (Shortest Job First): Optimal for minimizing average waiting time. However, it can suffer from starvation for longer jobs, especially in the preemptive version. Requires knowing future CPU burst times, which is often impossible in reality (predictive methods are used).
  • Round Robin: Fair algorithm that provides time-sharing. Good for interactive systems as it provides quick response times. However, performance is highly dependent on the size of the time quantum; too small increases context switching overhead, too large makes it behave like FCFS (First-Come, First-Served).
  • Priority Scheduling: Processes are executed based on priority. Can lead to starvation for low-priority processes. Can be preemptive or non-preemptive. Priorities can be static or dynamic.
  • FCFS (First-Come, First-Served): Simplest non-preemptive algorithm. Processes are served in the order they arrive. Can suffer from the "convoy effect" where a short process waits behind a long one.

The choice of scheduling algorithm impacts system performance significantly. The overhead of context switching is a key factor in evaluating the efficiency of preemptive algorithms, as frequent switches consume CPU cycles that could be used for executing processes.

Was this answer helpful?

Important Questions from Process Scheduling - Teaching

  1. Consider the following four processes with the arrival time and length of CPU burst given in milliseconds :

    ProcessArrival TimeBurst Time
    P 108
    P 214
    P 329
    P 435

    The average waiting time for preemptive SJF scheduling algorithm is

  2. Consider the following set of processes and the length of CPU burst time given in milliseconds:

    Process

    CPU Burst time (ms)

    P 1

    5

    P 2

    7

    P 3

    6

    P 4

    4

    Assume that processes being scheduled with Round-Robin Scheduling Algorithm with Time Quantum 4ms. Then the waiting time for P 4is _________ ms.

  3. Consider three intensive processes, which requires 10,20 and 30 units of time and arrive at times 0,2 and 6 respectively. how many context switches are needed if the operating system implements a shortest remaining time first scheduling algorithm? Do not count the context switches at time zero and at the end.

  4. Which of the following CPU scheduling algorithms is/are supported by LINUX operating system?

  5. Given CPU time slice of 2 ms and the following list of processes.

    Process

    Burst time (ms)

    Arrival time (ms)

    p 1

    3

    0

    p 2

    4

    2

    p 3

    5

    5

    Find average turnaround time and average waiting time using round-robin CPU scheduling?
Need Expert Advice?

Start Your Preparation with Prepp Mobile App

Download the app from Google Play & App Store
Download the app from Google Play & App Store
Prepp Mobile App