0% found this document useful (0 votes)
106 views7 pages

Flow Chart

This document describes a round-robin scheduling algorithm for processes using a queue. It outlines initializing a queue to hold processes, adding processes to the queue with their burst times, defining a time quantum, dequeuing processes to run for the quantum or until completion, re-enqueueing unfinished processes, and repeating until all processes finish to calculate waiting and turnaround times. A C program is provided that implements this algorithm, taking input for processes' arrival times and burst times, running in a loop based on the time quantum, and outputting performance metrics.

Uploaded by

Kavi Sanjai
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
106 views7 pages

Flow Chart

This document describes a round-robin scheduling algorithm for processes using a queue. It outlines initializing a queue to hold processes, adding processes to the queue with their burst times, defining a time quantum, dequeuing processes to run for the quantum or until completion, re-enqueueing unfinished processes, and repeating until all processes finish to calculate waiting and turnaround times. A C program is provided that implements this algorithm, taking input for processes' arrival times and burst times, running in a loop based on the time quantum, and outputting performance metrics.

Uploaded by

Kavi Sanjai
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 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