CPU Scheduling - Round Robin order on ready queue I am attempting the question below:


  Assume a set of processes $P_1, P_2, P_3$ and $P_4$ arrive at different times in the ready queue. The table below shows the burst time, the priority (smallest priority number implies highest priority) and arrival time for each of the processes.
  \begin{array}{|c|c|c|c|}
\hline
Process &amp; Burst ~ time &amp; Priority &amp; Arrival ~ Time \\ \hline
P_1 &amp; 8&amp; 2&amp; 0\\ \hline
P_2 &amp; 2 &amp; 3 &amp; 1 \\ \hline
P_3 &amp; 4 &amp; 1 &amp; 3 \\ \hline
P_4 &amp; 6 &amp; 2 &amp; 5 \\ \hline
\end{array}
  Draw a Gant chart, illustrating the execution of the processes, to demonstrate each of the following algorithms.
  
  
  First-Come, First-Served (FCFS)
  Round Robin(RR) with time slice of 3 time units. 
  


Problem I am having is that my answer is not matching what I am getting form the simulator here.

The problem might be with the way I am handling my ready Queue. My workings and answer is below. The simulator shows that after first time P3 appears in the chart that P4 should start. But P1 was pre-empted and still had more execution hence I put P1 in there. Where am I going wrong?

Ready Queue (as I was working it out):
P1,P2,P3,P1,P4,P3,P1,P4

GANT CHART:
With round-robin, the scheduler always selects the process that's had the most time since it was last run, and new processes coming in are always assigned a last run time of 1 time unit before the oldest last run time in the current list. (There are other equivalent ways to state this, but this is the simplest one for me. One other way to phrase this that works for many people is "processes that haven't had a chance to run yet have priority".)

So at t=8, we have:

Process Last-run Time-left
P1      0        5
P3      3        1
P4      -1*      6


Note the -1 for P4. The oldest last run time is P1, with 0. So P4 gets assigned -1, and hence gets selected.