You are on page 1of 7

FLOW CHART:

EXP NO:

DATE:

AIM:
To write a c program for application of queue using round-robin scheduling.

OBJECTIVE:
This program using queue in round-robin scheduling serves to ensure fairness,
responsiveness, and the prevention of starvation in a multi-tasking environment, making it a
commonly used scheduling algorithm in operating systems.

ALGORITHM:
1. Start the program.

2. Initialize a queue data structure to hold the processes. This queue will represent the ready
queue for scheduling.

3. Add all the processes that need to be scheduled to the queue, setting their initial burst
time and other necessary information.

4. Define a time quantum (also known as the time slice). This is the maximum amount of
time a process is allowed to execute in one go before being placed at the end of the queue.

5. Start a loop that continues until the queue is empty, indicating that all processes have
been executed.

6. Dequeue the first process from the queue.

7. Execute the process for the time quantum or until it completes, whichever comes first. If
the process doesn't finish within the time quantum, it's placed at the end of the queue.

8. If the process finishes, record its completion time and remove it from the system.

9. If the process does not finish, re-enqueue it at the end of the queue with its remaining
burst time adjusted.

10. Repeat the loop by going back to step 4 until all processes have been executed.

11. Calculate the turnaround time and waiting time for each process based on their
completion time and arrival time.

12. Stop the program.


PROGRAM:
#include<stdio.h>
int main()
{
int cnt,j,n,t,remain,flag=0,tq;
int wt=0,tat=0,at[10],bt[10],rt[10];
printf("Enter Total Process:\t ");
scanf("%d",&n);
remain=n;
for(cnt=0;cnt<n;cnt++)
{
printf("Enter Arrival Time and Burst Time for Process Process Number %d :",cnt+1);
scanf("%d",&at[cnt]);
scanf("%d",&bt[cnt]);
rt[cnt]=bt[cnt];
}
printf("Enter Time Quantum:\t");
scanf("%d",&tq);
printf("\n\nProcess\t|Turnaround Time|Waiting Time\n\n");
for(t=0,cnt=0;remain!=0;)
{
if(rt[cnt]<=tq && rt[cnt]>0)
{
t+=rt[cnt];
rt[cnt]=0;
flag=1;
}
else if(rt[cnt]>0
{
rt[cnt]-=tq;
t+=tq;
}
if(rt[cnt]==0 && flag==1)
{
remain--;
printf("P[%d]\t|\t%d\t|\t%d\n",cnt+1,t-at[cnt],t-at[cnt]-bt[cnt]);
wt+=t-at[cnt]-bt[cnt];
tat+=t-at[cnt];
flag=0;
}
if(cnt==n-1)
cnt=0;
else if(at[cnt+1]<=t)
cnt++;
else
cnt=0;
}
printf("\nAverage Waiting Time= %f\n",wt*1.0/n);
printf("Avg Turnaround Time = %f",tat*1.0/n);

return 0;
}

You might also like