This algorithm is designed for time-sharing systems.It is similar to FCFS,but a time quantum is introduced.CPU will be given to the process for one unit of time quantum.After that ,the process will be preempted and added back to ready queue.The ready queue will behave as a circular queue.The scheduler will go around the ready queue and allocates CPU for each process for a time interval of one time quantum.The value of time quantum here can be 10ms or 100ms.
There are two possibilities
- The process will not be completed in a one time quantum.Then,the context switch will happen and the current process is kept back at the tail of the ready queue and the next process in a ready queue is picked and allotted a CPU
- The process will be copleted within the duration of one time quantum.Then the process will give up the CPU voluntarily.Then,next process in a ready queue will be picked for execution
Example
Consider the processes P1 , P2 and P3 which are arrived at the time 0.Let the time quantum be 4 milliseconds.The burst time is given as below
| Process |
Burst Time |
| P1 |
24 |
| P2 |
3 |
| P3 |
3 |
The gantt chart will be
0 4 7 10 14 18 22 26 30
|
Note:
The burst time of processes P2 and P3 are lesser than the actual time quantum and hence, they will give up the CPU immediately after their completion
|
Waiting time for P1=0(first Pickup) + {10(next pickup)-4(previous CPU release)}=6
Waiting time for P2 = 4
Waiting time for P3 = 7
Average waiting time =(6+4+7)=5.67ms
Average turnaround time=(30+7+10)/3 = 15.67 ms
Throughput=3/30 = 0.1