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

Identify the circumstances under which pre-emptive CPU scheduling is used:

(a) A process switches from Running state to Ready state

(b) A process switches from Waiting state to Ready state

(c) A process completes its execution

(d) A process switches from Ready to Waiting state

Choose the correct option:

The correct answer is

(a) and (b) only

Understanding Pre-emptive CPU Scheduling

CPU scheduling is the process of deciding which of the processes in the ready queue should be allocated the CPU. Scheduling policies can be broadly classified into two categories: non-pre-emptive and pre-emptive.

In non-pre-emptive scheduling, once a process is allocated the CPU, it holds onto the CPU until it terminates or switches to the waiting state (e.g., for I/O). It does not release the CPU voluntarily unless it finishes or needs to wait for something.

In pre-emptive scheduling, the CPU can be taken away from a process before it finishes or voluntarily yields it. This usually happens when a higher-priority process arrives or when a process's allocated time slice expires (as in Round Robin scheduling).

Circumstances for Pre-emptive Scheduling Usage

Pre-emption involves the operating system forcefully taking the CPU away from a currently running process. Let's analyze the given circumstances:

(a) A process switches from Running state to Ready state

This transition ($\text{Running} \to \text{Ready}$) is a direct result of pre-emption. A process is running, and then the scheduler decides to move it back to the ready queue without it completing or waiting for I/O. Examples include:

  • A higher-priority process arrives, pre-empting the current lower-priority process.
  • The running process exhausts its allocated time slice (in time-sharing systems like Round Robin).
  • An interrupt occurs that requires the OS to run another process.

Therefore, this circumstance is when pre-emptive scheduling is used.

(b) A process switches from Waiting state to Ready state

This transition ($\text{Waiting} \to \text{Ready}$) occurs when an event a process was waiting for (like I/O completion) finally happens. The process becomes ready to run again. While this transition itself is not pre-emption, the *consequence* of a waiting process becoming ready can lead to pre-emption. If the newly ready process has a higher priority than the currently running process, the scheduler might pre-empt the running process to give the CPU to the new process. Thus, the occurrence of this event can trigger the scheduler to consider pre-emption.

Therefore, this circumstance is also relevant to the usage of pre-emptive scheduling mechanisms, as it's a point where the scheduler might decide to pre-empt.

(c) A process completes its execution

When a process finishes its execution, it terminates. This is a voluntary release of the CPU by the process itself. This is not pre-emption; it's a natural termination. The process moves from the Running state to the Terminated state.

Therefore, pre-emptive scheduling is not used when a process completes execution; non-pre-emptive scheduling also handles this case similarly.

(d) A process switches from Ready to Waiting state

The typical process state transitions do not include a direct switch from Ready ($\text{Ready} \to \text{Waiting}$). A process in the Ready state is waiting for the CPU. It moves to the Running state when the CPU is allocated. If it then needs to wait for an event (like I/O), it moves from Running to Waiting ($\text{Running} \to \text{Waiting}$). A transition directly from Ready to Waiting does not represent a standard scenario, nor does it involve pre-emption of a running process.

Summary of Scenarios and Pre-emption

Let's summarize how each scenario relates to pre-emptive scheduling:

Scenario Process Transition Relation to Pre-emption
(a) Process switches from Running to Ready $\text{Running} \to \text{Ready}$ This is pre-emption.
(b) Process switches from Waiting to Ready $\text{Waiting} \to \text{Ready}$ Can trigger pre-emption (if new process has higher priority).
(c) Process completes execution $\text{Running} \to \text{Terminated}$ This is not pre-emption; it's voluntary termination.
(d) Process switches from Ready to Waiting $\text{Ready} \to \text{Waiting}$ Not a standard transition; not related to pre-emption.

Based on this analysis, circumstances (a) and (b) are the ones under which pre-emptive CPU scheduling is used or can be triggered.

Revision Table: Key Concepts

Concept Description
CPU Scheduling Manages which process gets the CPU and for how long.
Pre-emptive Scheduling Allows the OS to take the CPU away from a running process.
Non-pre-emptive Scheduling Process keeps CPU until it finishes or blocks.
Process States Life cycle of a process (e.g., Ready, Running, Waiting).

Additional Information: Pre-emption Triggers

Pre-emption in CPU scheduling is primarily triggered by events that require the operating system to potentially re-evaluate which process should be running. Key triggers include:

  • Interrupts: Hardware or software interrupts can signal events (like I/O completion, timer expiry) that cause the CPU to switch context. If the interrupt handler determines a different process should run, pre-emption occurs.
  • Timer Expiration: In time-sharing systems, a timer interrupt signals the end of a process's time slice, leading to pre-emption and moving the process back to the ready queue.
  • Arrival of a Higher-Priority Process: In priority-based pre-emptive scheduling, if a new process arrives or a waiting process becomes ready and has a higher priority than the currently running process, the running process is pre-empted.
  • System Calls: Certain system calls (though less common as direct pre-emption triggers) can potentially lead to rescheduling, where pre-emption might occur based on algorithm rules.

Circumstances (a) and (b) directly relate to the outcomes or triggers of these events, making them the scenarios where pre-emptive scheduling is applicable.

Was this answer helpful?

Important Questions from Process

  1. A computer system has 7 tape drives. There are ‘n’ processes competing for them. Each process may need 2 tape drives. What is the maximum value of ‘n’ for which the system is guaranteed to be deadlock free?

  2. Match List I with List II

    List I

    List II

    System calls

    Description

    A.

    fork()

    I.

    Sends a signal from one process to another process

    B.

    exec()

    II.

    Indicates termination of the current process

    C.

    kill()

    III.

    Loads the specified program in the memory

    D.

    exit()

    IV.

    Creates a child process

    Choose the correct answer from the options given below :

  3. Assuming that the system call fork () never fails, consider the following C programs P1 and P2 executed on a UNIX / Linux system:

    /*P1*/

    Int main() {

    fork ():

    fork () ;

    fork () ;

    Printf(“Happy\n”);

    }

    /*P2*/

    Int main() {

    fork ();

    Printf(“Happy\n”);

    fork ()

    Printf(“Happy\n”);

    fork () ;

    Printf(“Happy\n”);

    }

    Statement I: P1 displays "Happy" 8 times.

    Statement II: P2 displays "Happy" 12 times.

    In the light of the above statements, choose the correct answer from the options given below

  4. ________ system call creates new process in Unix.

  5. The processes that are residing in main memory and are ready and waiting to be executed, are kept on a list called

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