Round Robin Scheduling Program in C

In this instructional exercise, you will find out about round-robin planning program in C.

Procedure booking is a significant part of the process the executives. In a multi-client and a

time-sharing framework, reaction time is one of the most significant targets to be practised.

There are many booking algorithms in C for process the board, for example,

First Come First Serve

Most limited Job First

Need Scheduling

Round Robin Scheduling Algorithm

Be that as it may, this instructional exercise will get you clear with comprehension of Round Robin Scheduling program in C.

Round Robin Scheduling Algorithm

The line structure is the prepared line is of First In First Out (FIFO) type.

A fixed time is designated to each procedure that lands in the line. This fixed time is known as time cut or time quantum.

The principal procedure that shows up is chosen and sent to the processor for execution.

In the event that it can’t finish its execution inside the time quantum gave, at that point a hinder is created utilizing a robotized timer.

The procedure is then halted and is sent back toward the finish of the line. In any case,

the state is spared and the setting is along these lines put away in memory. This encourages the

procedure to continue from the point where it interfered.

The scheduler chooses another procedure from the prepared line and dispatches it to the

processor for its execution. It is executed until the time Quantum doesn’t surpass.

Similar steps are rehashed until all the procedure are done.

The round-robin algorithm is basic and the overhead in basic leadership is low. It is the best

planning algorithm for accomplishing better and uniformly circulated reaction time.

Example

Let’s take one example to get it.

Time Quantum = 2

Process Arrival Time Burst Time
P109
P215
P323
P434
Process Arrival Time Burst Time (x) Turnaround Time(t) Normalized Turnaround Time(t/x) Waiting Time
P109212.3412
P215173.412
P323113.678
P4341238

Average Turnaround Time = 15.25
Average Normalized Turnaround Time = 3.10
Average Waiting Time = 10

Round Robin Scheduling Program in C

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

Output

Round Robin Scheduling Program in C

Leave a Comment

error: Alert: Content is protected!!