EXNO3_OS
EXNO3_OS
RESULT:
The FCFS scheduling algorithm has been implemented in C.
EX.NO.3B : IMPLEMENTATION OF SJF SCHEDULING ALGORITHM
DATE:
AIM
To write a C program to implement shortest job first (non-pre-emptive) scheduling
algorithm.
ALGORITHM:
Step 1: Start the program.
Step 2: Get the input process and their burst time. Step 3: Sort the processes based on burst
time.
Step 4: Compute the waiting time and turnaround time for each process. Step 5: Calculate
the average waiting time and average turnaround time. Step 6: Print the details about all the
processes.
Step 7: Stop the program.
PROGRAM:
#include<stdio.h>void main()
{
int i,j,n,bt[30],at[30],st[30],ft[30],wat[30],wt[30],temp,temp1,tot,tt[30];float awt, att; int
p[15];
wat[1]=0;
printf("ENTER THE NO.OF PROCESS");
scanf("%d",&n);
printf("\nENTER THE PROCESS NUMBER,BURST TIME AND ARRIVALTIME");
for(i=1;i<=n;i++)
{
scanf("%d\t %d\t %d",&p[i],&bt[i],&at[i]);
}
printf("\nPROCESS\tBURSTTIME\tARRIVALTIME");
for(i=1;i<=n;i++)
{
printf("\np%d\t%d\t\t%d",p[i],bt[i],at[i]);
}
for(i=1;i<=n;i++)
{
for(j=i+1;j<=n;j++)
{
if(bt[i]>bt[j])
{
temp=bt[i]; bt[i]=bt[j]; bt[j]=temp; temp1=p[i]; p[i]=p[j]; p[j]=temp1;
}
}
if(i==1)
{
}
else
{ st[1]=0;
ft[1]=bt[1]; wt[1]=0;
st[i]=ft[i-1];
ft[i]=st[i]+bt[i];
wt[i]=st[i];
}
}
printf("\n\n\t\t\tGANTT CHART\n"); printf("\n\n");
for(i=1;i<=n;i++)
printf("|\tp%d\t",p[i]); printf("|\t\n"); printf("\n\n");
printf("\n");
for(i=1;i<=n;i++)
printf("%d \t\t",wt[i]);
printf("%d",wt[n]+bt[n]); printf("\n \n"); for(i=2;i<=n;i++)
wat[i]=wt[i]-at[i]; for(i=1;i<=n;i++)
tt[i]=wat[i]+bt[i]-at[i]; printf("\nPROCESS\tBURSTTIME\tARRIVALTIME\tWAITINGTIME\tT
URNAROUNDTI ME\n");
for(i=1;i<=n;i++)
{
printf("\np%d %5d %15d %15d %15d",p[i],bt[i],at[i],wat[i],tt[i]);
}
for(i=1,tot=0;i<=n;i++)tot+=wt[i]; awt=(float)tot/n;
printf("\n\n\n AVERAGE WAITING TIME=%f",awt);for(i=1,tot=0;i<=n;i++) tot+=tt[i];
att=(float)tot/n;
printf("\n\n AVERAGE TURNAROUND TIME=%f",att);
}
OUTPUT:
enter the no.of process3
enter the process number,burst time and arrival time1 8 1
251
331
RESULT:
The SJF scheduling algorithm has been implemented in C.
EX.NO.3C:IMPLEMENTATION OF ROUND ROBIN SCHEDULING ALGORITHM
DATE:
AIM:
To write a C program to implement Round Robin scheduling algorithm.
ALGORITHM:
Step 1: Start the program.
Step 2: Get the input process and their burst time.Step
}
if(bt[i]==0) cwt=cwt+0;
wt[i]=wt[i]+(cwt-t[i]);
else if(bt[i]==max)
{
if(bt[i]>tq)
{
cwt=cwt+tq;
}
else
{
bt[i]=bt[i]-tq; max=max-tq;
}
else if(bt[i]<tq)
{
}
printf("|\t%s",p[i]); y[j]=cwt; j++;
ct=ct+1;
}
t[i]=cwt;
}
for(i=0;i<n;i++)
{
wt[i]=wt[i]-at[i]; a=a+wt[i]; tt[i]=wt[i]+b[i]-at[i]; s=s+tt[i];
}
a=a/n; s=s/n; printf("\n ");
printf("\n0"); for(i=0;i<j;i++)
printf("\t%d",y[i]); printf("\n");
printf("\n "); printf("\n\t\t ROUND ROBIN\n");
printf("\n Process Burst-time Arrival-time Waiting-time Turnaround-
time\n");
for(i=0;i<n;i++)
printf("\n\n %d%s \t %d\t\t %d \t\t %d\t\t %d", i+1, p[i], b[i], at[i],wt[i], tt[i]);
printf("\n\nAvg waiting time=%f",a);
printf("\n\nAvgturn around time=%f",s);
}
OUTPUT:
enter the no of process:3 enter the time quantum2
enter the process name, bursttime, arrival time
p1 2 0
p2 3 1
p3 4 2
GANTT CHART
| p1| p2| p3| p2| p3
0 2 4 6 7 9
ROUND ROBIN
RESULT
The Round Robin scheduling algorithm has been implemented in C.
EX.NO.3D: IMPLEMENTATION OF PRIORITY SCHEDULING ALGORITHM
DATE:
AIM
To write a C program to implement Priority Scheduling algorithm.
ALGORITHM:
Step 1: Start the program.
Step 2: Get the input process and their burst time. Step 3: Sort the processes based on
priority.
Step 4: Compute the waiting time and turnaround time for each process.
Step 5: Calculate the average waiting time and average turnaround time. Step 6: Print the
details about all the processes.
Step 7: Stop the program.
PROGRAM:
#include<stdio.h> #include<string.h>
void main()
{
int bt[30],pr[30],np; intwt[30],tat[30],wat[30],at[30],ft[30];int i,j,x,z,t; float
sum1=0,sum=0,awt,att;char
p[5][9],y[9];
printf("\nenter the number of process"); scanf("%d",&np);
printf("\nEnter the process,burst-time and priority:"); for(i=0;i<np;i++)
scanf("%s%d%d",p[i],&bt[i],&pr[i]); printf("\nEnter the arrival-time:"); for(i=0;i<np;i++)
scanf("%d",&at[i]); for(i=0;i<np;i++)
for(j=i+1;j<np;j++)
{
if(pr[i]>pr[j])
{
x=pr[j]; pr[j]=pr[i]; pr[i]=x; strcpy(y,p[j]);
strcpy(p[j],p[i]);
strcpy(p[i],y);
z=bt[j]; b t[j]=bt[i]; bt[i]=z;
}
} wt[0]=0;
for(i=1;i<=np;i++)
wt[i]=wt[i-1]+bt[i-1];
ft[0]=bt[0]; for(i=1;i<np;i++)
ft[i]=ft[i-1]+bt[i]; printf("\n\n\t\tGANTT CHART\n");printf("\n
\n"); for(i=0;i<np;i++)
printf("|\t%s\t",p[i]);
printf("|\t\n");
printf("\n \n");
printf("\n"); for(i=0;i<=np;i++)
printf("%d\t\t",wt[i]);
printf("\n \n");
printf("\n"); for(i=0;i<np;i++)
wat[i]=wt[i]-at[i]; for(i=0;i<np;i++)
tat[i]=wat[i]-at[i]; printf("\nPRIORITY SCHEDULING:\n");
printf("\nProcess Priority Burst-time Arrival-time Waiting-time Turnaround-time");
for(i=0;i<np;i++)
printf("\n\n%d%s\t%d\t\t%d\t\t%d\t%d\t\t%d",i+1,p[i],pr[i],bt[i],a t[i],wt[i],tat[i]);
for(i=0;i<np;i++)
sum=sum+wat[i]; awt=sum/np; for(i=0;i<np;i++)
sum1=sum1+tat[i]; att=sum1/np;
printf("\n\nAverage waiting time:%f",awt); printf("\n\nAverageturn aroundtime is:%f",att);
}
OUTPUT:
Enter the number of process3
Enter the process, burst-time and priority:p1 3 3 p2 4 2
p3 5 1
Enter the arrival-time: 0 1 2
GANTT CHART
| p3 | p2 | p1 |
0
5
9
12
PRIORITY SCHEDULING:
Process PriorityBurst-time Arrival-time Waiting-time Turnaround-time
p3 1 5 0 0 0
p2 2 4 1 5 3
p1 3 3 2 9 5
Average waiting time: 3.666667 Average turnaround time is: 2.666667
RESULT
The Priority scheduling algorithm has been implemented in C.