Special case scheduling

682 views Asked by At

So here's the question. While studying about process scheduling I came across two seemingly contradictory examples I just can't get my head around.

The problem arises if for instance in the priority non-preemptive scheduling algorithm which always chooses the process with the highest priority to be run next and once running, process can only volontarily give up its CPU time, that is no other process can run until the currently running process finishes. It seems that what the solution the book proposes is that if both end of one process and arrival of the new high-priority process occur at the same time, the new high-priority process will be added to the ready queue and then chosen by the scheduler to be run next.

But in the other example in Round-robin algorithm, if there is only one process in the ready queue and it is currently running, if at the same time its quantum elapses and new process says its ready, it seems that the proposed solution is that the scheduling will be done first, so the currently running process will continue to run while the new process will be added to the queue.

I'd be grateful if someone clarified this to me, because I know from some other post that context switch does not occur in round robin for single process in queue, but is it true in general that scheduling is done before adding new process to queue.

1

There are 1 answers

1
Philipp On BEST ANSWER

What I get from you description is:

Time 0:

Process 1 starts using its time slice, e.g. 5 units.

Time 5:

Process 2 arrives. Process 1 used up its time slice and is replenished.

A round robin scheduler checks the ready queue by selecting the next process with time left. At time 0 your ready queue looks like this:

P1

At time 5:

P1 going over to P1 -> P2

Tanenbaum writes in Modern Operating Systems: When a process used up it's time slice, it is enqueued at the end. So what happens is, that P1 is enqueued again before P2 is enqueued for the first time. This saves an additional context switch from P1 to P2 and back to P1. If you want P2 to be run first, then you can use priority base round robin.