Experiment No. - 1: Aim: Software Used: Language Used: Code
Experiment No. - 1: Aim: Software Used: Language Used: Code
Experiment No. - 1: Aim: Software Used: Language Used: Code
EXPERIMENT NO. – 1
AIM: Write a C program to implement the First Come First Serve Algorithm.
SOFTWARE USED: Dev C++ (version 5.11)
LANGUAGE USED: C
CODE:
#include <stdio.h>
int main()
{
int bt[10],at[10], tat[10],wt[10]={0},ct[10]={0};
int n,i,j,k, sum = 0;
float totalTAT=0, totalWT=0;
printf("Name of student = SARITA G. BIJAWE \n Student ID =
17004027 \n\n");
printf("Enter no. of processes ");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("Arrival Time of Process[%d] ",i+1);
scanf("%d",&at[i]);
printf("Burst Time of Process[%d] ",i+1);
scanf("%d",&bt[i]);
printf("\n");
}
for(j=0;j<n;j++)
{
sum+=bt[j];
ct[j]+=sum;
}
for(k=0;k<n;k++)
{
tat[k]=ct[k]-at[k];
totalTAT+=tat[k];
}
for(k=0;k<n;k++)
{
wt[k]=tat[k]-bt[k];
totalWT+=wt[k];
}
printf("Solution: \n\n");
printf("P#\t AT\t BT\t CT\t TAT\t WT\t\n\n");
for(i=0;i<n;i++)
{
printf("P%d\t %d\t %d\t %d\t %d\t %d\n ",i+1,at[i],bt[i],
ct[i],tat[i],wt[i]);
ETU807 OSOS LAB STUDENT ID: 17004027
}
printf("\n\nAverage TurnAround Time = %f\n",totalTAT/n);
printf("Average WT = %f\n\n",totalWT/n);
return 0;
}
OUTPUT:
CONCLUSION: The First Come First Serve CPU scheduling Algorithm has been successfully
simulated in this program. The FCFS scheduling is performed on the basis of arrival time of
the processes irrespective of their other parameters.
ETU807 OSOS LAB STUDENT ID: 17004027
EXPERIMENT NO. – 2
AIM: Write a C program to implement the Shortest Job First Algorithm.
SOFTWARE USED: Dev C++ (version 5.11)
LANGUAGE USED: C
CODE:
#include<stdio.h>
int main()
{
int i,n,p[10]={1,2,3,4,5,6,7,8,9,10},min,k=1,btime=0;
int bt[10],temp,j,at[10],wt[10],tt[10],ta=0,sum=0;
float wavg=0,tavg=0,tsum=0,wsum=0;
printf("Name of student = SARITA G. BIJAWE \n Student ID =
17004027 \n\n");
for(j=0;j<n;j++)
{
btime=btime+bt[j];
min=bt[k];
for(i=k;i<n;i++)
{
if (btime>=at[i] && bt[i]<min)
{
temp=p[k];
p[k]=p[i];
p[i]=temp;
temp=at[k];
at[k]=at[i];
at[i]=temp;
temp=bt[k];
bt[k]=bt[i];
bt[i]=temp;
}
}
k++;
}
wt[0]=0;
for(i=1;i<n;i++)
{
sum=sum+bt[i-1];
wt[i]=sum-at[i];
wsum=wsum+wt[i];
}
wavg=(wsum/n);
for(i=0;i<n;i++)
{
ta=ta+bt[i];
tt[i]=ta-at[i];
tsum=tsum+tt[i];
}
tavg=(tsum/n);
printf("************************");
printf("\n RESULT:-");
printf("\nProcess\t Burst\t Arrival\t Waiting\t Turn-around"
);
for(i=0;i<n;i++)
{
printf("\n p%d\t %d\t %d\t\t
%d\t\t\t%d",p[i],bt[i],at[i],wt[i],tt[i]);
}
printf("\n\nAVERAGE WAITING TIME : %f",wavg);
ETU807 OSOS LAB STUDENT ID: 17004027
CONCLUSION: The Shortest Job First CPU scheduling Algorithm has been successfully
simulated in this program. The SJF scheduling is performed based on the duration of burst
time of the process and if needed FCFS approach is also used in case of same burst time.
ETU807 OSOS LAB STUDENT ID: 17004027
EXPERIMENT NO. – 3
AIM: Write a C program to implement the Non Pre-emptive Priority Algorithm.
SOFTWARE USED: Dev C++ (version 5.11)
LANGUAGE USED: C
CODE:
#include<stdio.h>
int main()
{
int bt[20],p[20],wt[20],tat[20],pr[20],i,j,n,total=0;
int pos,temp,avg_wt,avg_tat;
printf("Name of student = SARITA G. BIJAWE \n Student ID =
17004027 \n\n");
temp=bt[i];
bt[i]=bt[pos];
bt[pos]=temp;
temp=p[i];
p[i]=p[pos];
ETU807 OSOS LAB STUDENT ID: 17004027
p[pos]=temp;
}
OUTPUT:
ETU807 OSOS LAB STUDENT ID: 17004027
CONCLUSION: The Non pre-emptive Priority CPU scheduling Algorithm has been
successfully simulated in this program. The Priority scheduling is performed based on the
priority assigned to the process and if needed FCFS approach is also used in case of same
priority.
ETU807 OSOS LAB STUDENT ID: 17004027
EXPERIMENT NO. – 4
AIM: Write a C program to implement the Non Pre-emptive Round Robin Algorithm.
SOFTWARE USED: Dev C++ (version 5.11)
LANGUAGE USED: C
CODE:
#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("Name of student = SARITA G. BIJAWE \n Student ID =
17004027 \n\n");
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];
ETU807 OSOS LAB STUDENT ID: 17004027
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:
ETU807 OSOS LAB STUDENT ID: 17004027
CONCLUSION: The Non pre-emptive Round Robin CPU scheduling Algorithm has been
successfully simulated in this program. The Round Robin scheduling is performed by giving
equal chance to every process using the assigned Time Slice value.
ETU807 OSOS LAB STUDENT ID: 17004027
EXPERIMENT NO. – 5
AIM: Write a C program to implement the Pre-emptive Priority Scheduling Algorithm.
SOFTWARE USED: Dev C++ (version 5.11)
LANGUAGE USED: C
CODE:
#include<stdio.h>
struct process
{
char process_name;
int arrival_time, burst_time, ct, waiting_time,
turnaround_time, priority;
int status;
}process_queue[10];
int limit;
void Arrival_Time_Sorting()
{
struct process temp;
int i, j;
for(i = 0; i < limit - 1; i++)
{
for(j = i + 1; j < limit; j++)
{
if(process_queue[i].arrival_time >
process_queue[j].arrival_time)
{
temp = process_queue[i];
process_queue[i] = process_queue[j];
process_queue[j] = temp;
}
}
}
}
void main()
{
int i, time = 0, burst_time = 0, largest;
char c;
float wait_time = 0, turnaround_time = 0,
average_waiting_time, average_turnaround_time;
printf("Name of student = SARITA G. BIJAWE \n Student ID =
17004027 \n\n");
ETU807 OSOS LAB STUDENT ID: 17004027
printf("\n%c\t\t%d\t\t%d\t\t%d\t\t%d",
process_queue[largest].process_name,
process_queue[largest].arrival_time,
process_queue[largest].burst_time,
process_queue[largest].priority,
process_queue[largest].waiting_time);
}
average_waiting_time = wait_time / limit;
average_turnaround_time = turnaround_time / limit;
printf("\n\nAverage waiting time:\t%f\n",
average_waiting_time);
printf("Average Turnaround Time:\t%f\n",
average_turnaround_time);
}
OUTPUT:
ETU807 OSOS LAB STUDENT ID: 17004027
EXPERIMENT NO. – 6
AIM: Write a C program to implement the Bankers algorithm for the purpose of deadlock
avoidance.
int main()
{
int Max[10][10], need[10][10], alloc[10][10], avail[10],
completed[10], safeSequence[10];
int p, r, i, j, process, count;
count = 0;
printf("Name of student = SARITA G. BIJAWE \n Student ID =
17004027 \n\n");
do
{
printf("\n Max matrix:\tAllocation matrix:\n");
for(i = 0; i < p; i++)
{
for( j = 0; j < r; j++)
printf("%d ", Max[i][j]);
printf("\t\t");
for( j = 0; j < r; j++)
printf("%d ", alloc[i][j]);
printf("\n");
}
process = -1;
if(process != -1)
{
printf("\nProcess %d runs to completion!",
process + 1);
safeSequence[count] = process + 1;
count++;
for(j = 0; j < r; j++)
ETU807 OSOS LAB STUDENT ID: 17004027
{
avail[j] += alloc[process][j];
alloc[process][j] = 0;
Max[process][j] = 0;
completed[process] = 1;
}
}
}while(count != p && process != -1);
if(count == p)
{
printf("\nThe system is in a safe state!!\n");
printf("Safe Sequence : < ");
for( i = 0; i < p; i++)
printf("%d ", safeSequence[i]);
printf(">\n");
}
else
printf("\nThe system is in an unsafe state!!");
getch();
}
OUTPUT:
ETU807 OSOS LAB STUDENT ID: 17004027
CONCLUSION: The Bankers Algorithm for Deadlock Avoidance has been simulated
successfully in this program. It is applicable to a system with multiple instances of each
resource type. To decide whether the current request can be satisfied or must be delayed,
the system must consider the resources currently available, the resources currently
allocated to each process, and the future requests and releases of each process.
ETU807 OSOS LAB STUDENT ID: 17004027
EXPERIMENT NO. – 7
AIM: Write a C program to implement the FIFO Page Replacement algorithm.
SOFTWARE USED: Dev C++ (version 5.11)
LANGUAGE USED: C
CODE:
#include<stdio.h>
#include<conio.h>
int main()
{
int i,j,k,f, pf=0, count=0,rs[25],m[10],n;
printf("Name of student = SARITA G. BIJAWE \n Student ID =
17004027 \n\n");
}
OUTPUT:
CONCLUSION: The FIFO Page replacement algorithm has been successfully simulated in
this program. It is the simplest page replacement method in which the operating system
maintains all the pages in a queue, oldest pages are kept in the front and newest are kept at
the end. On a page fault, these pages from the front are removed first, and the pages in
demand are added.
ETU807 OSOS LAB STUDENT ID: 17004027
EXPERIMENT NO. – 8
AIM: Write a C program to implement the Least Recently Used(LRU) Page Replacement
algorithm.
int main()
{
int i,j,k,min,rs[25],m[10],count[10],flag[25],n,f,pf=0,next=1;
printf("Name of student = SARITA G. BIJAWE \n Student ID =
17004027 \n\n");
count[i]=next;
next++;
}
else
{
min=0;
for(j=1;j<f;j++)
if(count[min]>count[j])min=j;
m[min]=rs[i];
count[min]=next;
next++;
}
pf++;
}
for(j=0;j<f;j++)
printf("%d\t", m[j]);
if(flag[i]==0)
printf("PF No. %d" , pf);
printf("\n");
}
printf("\nThe number of page faults using LRU are %d",pf);
}
OUTPUT:
ETU807 OSOS LAB STUDENT ID: 17004027