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:
(a) and (b) only
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).
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:
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.
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.
| 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). |
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:
Circumstances (a) and (b) directly relate to the outcomes or triggers of these events, making them the scenarios where pre-emptive scheduling is applicable.
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?
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 :
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
________ system call creates new process in Unix.
The processes that are residing in main memory and are ready and waiting to be executed, are kept on a list called