This is my first post in here... here goes...
I'm stuck at trying to understand how does round robin work.
I understand that round robin is an algorthim that allocates an amount of timeslice to each process to provide a best possible fair allocation of CPU processing time. Each process is allocated up to the pre-determined timeslice for processing and the CPU would switch to another process. The order of which process obtains usage of the CPU is determined by the order the processes arrive.
But I am unsure what happens in the following scenario:
timeslice: 2 seconds
pid arrivalTime duration (in seconds)
1 0 5
2 4 8
3 6 9
4 8 10
p1 (process with pid of 1) would be using the CPU for 4 seconds (i.e. 2 timeslices). At the 4th second, when p1 has just finished using the CPU, p2 arrives. The waiting queue for using the CPU is empty. At this instance, is where I am unsure what happens.
Question: Does p1 continue to get the timeslice and p2 gets put into the waiting queue OR p1 gets put onto the waiting queue and p2 get usage of the CPU?
I would greatly appreciate it if someone could answer my query. I referred to a few textbooks, their examples did not mention about this explicit scenario. I need to do a programming assignment on this thus really need to understand how it works before I can begin doing it.