0
$\begingroup$

If we have only one submitted process and we are using RR CPU scheduling algorithm. Assume that the CPU burst time for this process is 10 ms and the time quantum is 2 , then there will be multiple context switches ? OR the process will continue running on the CPU ? The book "Operating system concepts" 9th edition , page 273 , states that :

Assume, for example, that we have only one process of 10 time units. If the quantum is 12 time units, the process finishes in less than 1 time quantum, with no overhead. If the quantum is 6 time units, however, the process requires 2 quanta, resulting in a context switch. If the time quantum is 1 time unit, then nine context switches will occur, slowing the execution of the process accordingly (Figure 6.4).

Which means that there will be context switch for one process only . However , this doesn't make any sense for me , since we have only one process , so why the OS performs context switch ?

$\endgroup$
1
  • $\begingroup$ Unless scheduling is stopped, after a quantum the scheduler needs to be called. That means that at least some context of the (only) process must be saved. $\endgroup$
    – user16034
    Commented Apr 5, 2022 at 8:02

1 Answer 1

1
$\begingroup$

A round robin scheduling algorithm schedules a fixed time slice/quantum for every process. Every process arrives in the ready queue and the short term scheduler decides which process to dispatch next based on the scheduling algorithm.

I think you are assuming context switch to be the process of interrupting one process and running another one, which is alright most of the times but isn't exact. A context switch means saving the current state of the process so that it can resume execution later.

As you see, the short term scheduler and scheduling algorithms operate on the ready queue, where the processes are in ready state. So in running state assuming a uniprocessor system, the OS simply keeps the process in running state as per the scheduling algorithm. So in this case even if there is just 1 process, after using up its time slice, it would save the current execution state, go back to the ready queue and be scheduled to run again. Hence the context switch. Hope this clears your doubt.

The lines in the text are based on a lot of assumptions, primarily assuming that only 1 process is to be run on the cpu, which isn't how modern OSes work in practice. There are much more processes and even the OS itself(the core of the OS called kernel) which need to run in a multitasking fashion to ensure the OS delivers the performance and functionality it's supposed to.

$\endgroup$
1
  • 2
    $\begingroup$ Just as an additional comment: Operating systems often optimise for the case of returning to the same task that the kernel entry came from. The obvious example is a system call that doesn't block, but preemption could easily use the same mechanism: if a task uses its quantum, it is preempted, but the OS finds that no other task of higher or equal priority is ready, just return. $\endgroup$
    – Pseudonym
    Commented Apr 5, 2022 at 3:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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