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

Round Robin & Priority CPU Scheduling Lab

The document outlines two experiments for a computer science assignment focusing on CPU scheduling algorithms: Round Robin and Non-Preemptive Priority Scheduling. Each experiment includes a description of the algorithm, source code for implementation, and a discussion on its characteristics and advantages. The aim is to calculate average waiting and turnaround times for processes using these scheduling methods.

Uploaded by

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

Round Robin & Priority CPU Scheduling Lab

The document outlines two experiments for a computer science assignment focusing on CPU scheduling algorithms: Round Robin and Non-Preemptive Priority Scheduling. Each experiment includes a description of the algorithm, source code for implementation, and a discussion on its characteristics and advantages. The aim is to calculate average waiting and turnaround times for processes using these scheduling methods.

Uploaded by

imariful18
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

D

EPARTMENT OF COMPUTER SCIENCE AND


ENGINEERING

Assignment
Course Code: CSE-3632
Course Title: Operating Systems Lab.
Student Name: MD ARIFUL ISLAM
Student ID: C191079
Semester: Autumn-2021
Section: 6BM
Student Contact No: 01521219552
Student Email: imariful18@[Link]
Student g-suite: c191079@[Link]

Course Instructor: Mr. Md Shafiul Alam Farhad.


Assistant professor,
Department of CSE, CUET.
Experiment (II)

Round Robin CPU Scheduling Algorithm


DESCRIPTION:
To aim is to calculate the average waiting time. There will be a time slice, each process
should be executed within that time-slice and if not, it will go to the waiting state so first
check whether the burst time is less than the time-slice. If it is less than it assigns the
waiting time to the sum of the total times. If it is greater than the burst-time then subtract
the time slot from the actual burst time and increment it by time-slot and the loop
continues until all the processes are completed.

Source Code
#include<stdio.h>
#include<conio.h>
void main()
{
int i, NOP, sum=0, count=0, y, quant, wt=0, tat=0, at[10], bt[10], temp[10];
float avg_wt, avg_tat;
printf(" Total number of process in the system: ");
scanf("%d", &NOP);
y = NOP;
for (i=0; i<NOP; i++)
{
printf("\n Enter the Arrival and Burst time of the Process[%d]\n", i+1);
printf(" Arrival time is: \t");
scanf("%d", &at[i]);
printf(" Burst time is : \t");
scanf("%d", &bt[i]);
temp[i] = bt[i];
}
printf ("Enter the Time Quantum for the process: \t");
scanf("%d", &quant);
printf("\n Process No \t\t Burst Time \t\t TAT \t\t Waiting Time ");
for (sum=0, i = 0; y!=0; )
{
if(temp[i] <= quant && temp[i] > 0)
{
sum = sum + temp[i];
temp[i] = 0;
count=1;
}
else if(temp[i] > 0)
{
temp[i] = temp[i] - quant;
sum = sum + quant;
}
if(temp[i]==0 && count==1)
{
y--;
printf("\nProcess No[%d] \t\t %d\t\t\t\t %d\t\t\t %d", i+1, bt[i], sum-at[i], sum-at[i]-
bt[i]);
wt = wt+sum-at[i]-bt[i];
tat = tat+sum-at[i];
count =0;
}
if(i==NOP-1)
{
i=0;
}
else if(at[i+1] <=sum)
{
i++;
}
else
{
i=0;
}
}
avg_wt = wt * 1.0/NOP;
avg_tat = tat * 1.0/NOP;
printf("\n Average Turn Around Time: \t%f", avg_wt);
printf("\n Average Waiting Time: \t%f", avg_tat);
getch();
};
Input and output
Discussion:

A round-robin is a CPU scheduling algorithm that shares equal portions of resources in


circular orders to each process and handles all processes without prioritization. It does
not face any starvation issues or convoy effect. Each process gets equal priority to the
fair allocation of CPU. It is easy to implement the CPU Scheduling algorithm. Each new
process is added to the end of the ready queue as the next process's arrival time is
reached. Each process is executed in circular order that shares a fixed time slot or
quantum. Every process gets an opportunity in the round-robin scheduling algorithm to
reschedule after a given quantum period.

Experiment (II)

Priority Non-Preemptive CPU Scheduling Algorithm:

DESCRIPTION:

To calculate the average waiting time in the priority algorithm, sort the burst Times
according to their priorities and then calculate the average waiting time of the
Processes. The waiting time of each process is obtained by summing up the burst times
of all the previous processes.

Source Code:
#include<stdio.h>
main()
{
int p[20],bt[20],pri[20], wt[20],tat[20],i, k, n, temp;
float wtavg,tatavg;
printf("Enter the number of processes : ");
scanf("%d",&n);
for(i=0; i<n; i++)
{
p[i] = i;
printf("Enter the Burst Time & Priority of Process %d : ",i);
scanf("%d%d",&bt[i], &pri[i]);
}
for(i=0; i<n; i++)
for(k=i+1; k<n; k++)
if(pri[i] > pri[k])
{
temp=p[i];
p[i]=p[k];
p[k]=temp;
temp=bt[i];
bt[i]=bt[k];
bt[k]=temp;
temp=pri[i];
pri[i]=pri[k];
pri[k]=temp;
}
wtavg = wt[0] = 0;
tatavg = tat[0] = bt[0];
for(i=1; i<n; i++)
{
wt[i] = wt[i-1] + bt[i-1];
tat[i] = tat[i-1] + bt[i];
wtavg = wtavg + wt[i];
tatavg = tatavg + tat[i];
}
printf("\nPROCESS\t\tPRIORITY\tBURST TIME\tWAITING TIME\
tTURNAROUNDTIME");

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


printf("\n%d \t\t %d \t\t %d \t\t %d \t\t %d ",p[i],pri[i],bt[i],wt[i],tat[i]);
printf("\nAverage Waiting Time is : %f",wtavg/n);
printf("\nAverage Turnaround Time is : %f",tatavg/n);
getch();
}
Input And Output:

Discussion:
In the Non-Preemptive Priority scheduling, The Processes are scheduled according to
the priority number assigned to them. Once the process gets scheduled, it will run till the
completion. Generally, the lower the priority number, the higher is the priority of the
process. The people might get confused with the priority numbers, hence in the GATE,
there clearly mention which one is the highest priority and which one is the lowest one.

You might also like