principleMinor
Difficulty understanding pre-emptive vs non-preemptive CPU scheduling
Viewed 0 times
understandingschedulingnonemptiveprecpudifficultypreemptive
Problem
I'm having difficulty understanding what my book is trying to say in regards to preemptive and non-preemptive CPU scheduling.
It says the following:
CPU Scheduling decisions may take place under the following four
circumstances:
-
When a process switches from the running state to the waiting state (for example, I/O request..)
-
When a process switches from the running state to the ready state (for example, when an interrupt occurs)
-
When a process switches from the waiting state to the ready state (for example, completion of I/O)
-
When a process terminates
In circumstances 1 and 4, there is no choice in terms of scheduling. A new process (if one exists in the ready queue) must be selected for
execution. There is a choice, however, in circumstances 2 and 3.
When scheduling takes place only under circumstances 1 and 4, we say
that the scheduling scheme is non-preemtive; otherwise, the scheduling
scheme is preemptive. Under nonpreemptive scheduling, once the CPU has
been allocated to a process, the process keeps the CPU until it
releases the CPU either by terminating or by switching to the waiting
state.
It is mainly the bolded part that confuses me. What does it mean by there "being a choice"? The way it's worded almost sounds like it's saying that in circumstances 2 and 3, a new process DOESN'T have to be selected for execution. I'm not quite sure I follow at all what this section of my book is trying to tell me, especially the bolded part.
It says the following:
CPU Scheduling decisions may take place under the following four
circumstances:
-
When a process switches from the running state to the waiting state (for example, I/O request..)
-
When a process switches from the running state to the ready state (for example, when an interrupt occurs)
-
When a process switches from the waiting state to the ready state (for example, completion of I/O)
-
When a process terminates
In circumstances 1 and 4, there is no choice in terms of scheduling. A new process (if one exists in the ready queue) must be selected for
execution. There is a choice, however, in circumstances 2 and 3.
When scheduling takes place only under circumstances 1 and 4, we say
that the scheduling scheme is non-preemtive; otherwise, the scheduling
scheme is preemptive. Under nonpreemptive scheduling, once the CPU has
been allocated to a process, the process keeps the CPU until it
releases the CPU either by terminating or by switching to the waiting
state.
It is mainly the bolded part that confuses me. What does it mean by there "being a choice"? The way it's worded almost sounds like it's saying that in circumstances 2 and 3, a new process DOESN'T have to be selected for execution. I'm not quite sure I follow at all what this section of my book is trying to tell me, especially the bolded part.
Solution
In circumstances 1 and 4, the current process can't continue running. Therefore, there's no choice: the OS scheduler has to step in and select a different process.
In circumstances 2 and 3, the OS scheduler has a choice: it can either allow the current process to continue running, or it could step in and put the current process to sleep and select a different process to run. The latter operation is called "preempting" the current process and scheduling a new one to run.
So, yes, your understanding sounds about right.
In circumstances 2 and 3, the OS scheduler has a choice: it can either allow the current process to continue running, or it could step in and put the current process to sleep and select a different process to run. The latter operation is called "preempting" the current process and scheduling a new one to run.
So, yes, your understanding sounds about right.
Context
StackExchange Computer Science Q#47926, answer score: 7
Revisions (0)
No revisions yet.