0% found this document useful (0 votes)
6 views

Write A Program For Implementing The Round Robin Scheduling Algorithm

Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

Write A Program For Implementing The Round Robin Scheduling Algorithm

Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

Write a program for implementing the round robin Scheduling algorithm

AIM:

To write a program for implement the round robin scheduling algorithm

ALGORITHM:

1. Start the process.


2. Declare the array size.
3. Get the number of elements to be inserted.
4. Get the value.
5. Set the time sharing system with preemption.
6. Define quantum is defined from 10 to 100ms.
7. Declare the queue as a circular.
8. Make the CPU scheduler goes around the ready queue allocating CPU to each

process for the time interval specified.


9. Make the CPU scheduler picks the first process and sets time to interrupt after
quantum expired dispatches the process.
10. If the process has burst less than the time quantum than the process releases
the CPU.

PROGRAM:

#include<stdio.h>
main()
{

int pt[10][10],a[10][10],at[10],pname[10][10],i,j,n,k=0,q,sum=0;

float avg;
printf("\n\n Enter the number of processes : ");
scanf("%d",&n);
for(i=0;i<10;i++)
{

for(j=0;j<10;j++)
{
pt[i][j]=0;
a[i][j]=0;
}

}
for(i=0;i<n;i++)

{
j=0;
printf("\n\n Enter the process time for process %d : ",i+1);
scanf("%d",&pt[i][j]);

}
printf("\n\n Enter the time slice : ");

scanf("%d",&q);
printf("\n\n");
for(j=0;j<10;j++)
{

for(i=0;i<n;i++)

{
a[2*j][i]=k;
if((pt[i][j]<=q)&&(pt[i][j]!=0))

pt[i][j+1]=0;
printf(" %d P%d %d\n",k,i+1,k+pt[i][j]);
k+=pt[i][j];
a[2*j+1][i]=k;

}
else if(pt[i][j]!=0)

{
pt[i][j+1]=pt[i][j]-q;
printf(" %d P%d %d\n",k,i+1,(k+q));
k+=q;
a[2*j+1][i]=k;

}
else

{
a[2*j][i]=0;
a[2*j+1][i]=0;

}
}
}
for(i=0;i<n;i++)

sum+=a[0][i];
for(i=0;i<n;i++)
{

for(j=1;j<10;j++)
{
if((a[j][i]!=0)&&(a[j+1][i]!=0)&&((j+1)%2==0))
sum+=((a[j+1][i]-a[j][i]));
}
}
avg=(float)sum/n;

printf("\n\n Average waiting time = %f msec",avg);


sum=avg=0;
for(j=0;j<n;j++)

{
i=1;
while(a[i][j]!=0)
i+=1;
sum+=a[i-1][j];

}
avg=(float)sum/n;
printf("\n\n Average turnaround time = %f msec\n\n",avg);
}

OUTPUT:

[root@localhost ~]# ./a.out


Enter the number of processes : 4

Enter the process time for process 1 : 8 Enter the process time for process 2 : 3 Enter
the process time for process 3 : 6 Enter the process time for process 4 : 1

Enter the time slice

: 2 0 P1 2
2 P2 4
4 P3 6
6 P4 7
7 P1 9
9 P2 10
10 P3 12
12 P1 14
14 P3 16
16 P1 18

Average waiting time = 8.250000 msec


Average turnaround time = 12.750000
msec

You might also like