-2

Operating System Concepts says

CPU-scheduling decisions may take place under the following four circum- stances:

  1. When a process switches from the running state to the waiting state (for example, as the result of an I/O request or an invocation of wait() for the termination of a child process)

  2. When a process switches from the running state to the ready state (for example, when an interrupt occurs)

  3. When a process switches from the waiting state to the ready state (for example, at completion of I/O)

  4. When a process terminates

For situations 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, for situations 2 and 3.

When scheduling takes place only under circumstances 1 and 4, we say that the scheduling scheme is nonpreemptive or cooperative. Otherwise, it is preemptive.

What does "choice in terms of scheduling" mean?

Why is there no choice for cooperative scheduling, and there may be for preemptive scheduling?

I think that whether scheduling is preemptive or not,

  • the running process always gives up the CPU (so no choice), and

  • there is always a choice to make to select one process from the ready queue to run.

Thanks.

2

The text says that when there is no choice,

A new process (if one exists in the ready queue) must be selected for execution.

I take this to mean that the choice being discussed isn’t directly about which process to schedule next, but rather whether the process being examined can be scheduled. In cases 1 and 4, it can’t. In cases 2 and 3, it can.

The cooperative v. preemptive terminology used here seems weird to me; cooperative scheduling usually means that processes yield control voluntarily, but interpreting “being blocked” and “terminating” as cooperative scheduling is somewhat far-fetched in my opinion.

  • Thanks. Is it correct that changing the state of a process from running or waiting to ready can only be done by preemptive scheduling? – Tim Oct 8 '18 at 21:51
  • The “running to ready” transition is characteristic of preemptive scheduling, if it’s external; in cooperative scheduling, such a transition is possible when the running process yields. The “waiting to ready” transition isn’t specific to preemptive scheduling; in a cooperative model which yields on I/O, you’d need such a transition too. – Stephen Kitt Oct 9 '18 at 8:13
1

In cases 1 & 4 the process has no work to do (in case 1 yet, in case 4 ever) and therefore can't be run by the scheduler. i.e. there's not choice to be made: run or don't run... it's always don't run. There's a choice in the cases of 2 and 3 because the scheduler has to decide 'do I run this process or a different one?' But only a preemptive scheduler will make that choice, a cooperative scheduler will wait until the running process is in state 1 (i.e. waiting for i/o or yielding) or 4 (terminated either successfully or with an error)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.