OPERATING SYSTM’s ALGORITHM (In LINUX OS) - FIRST COME FIRST SERVE SCHEDULING
FIRST COME FIRST SERVE SCHEDULING
PROGRAM:
#include<stdio.h>
struct fcfs
{
int at,st,ct,tt;
}f[10];
main()
{
int no;
int i,d;
printf(“\nEnter the number of jobs”);
scanf(“%d”,&no);
for(i=0;i<no;i++)
{
printf(“\nEnter the arrival time for job %d”,i+1);
scanf(“%d”,&f[i].at);
printf(“\nEnter the service time for job %d”,i+1);
scanf(“%d”,&f[i].st);
}
f[-1].ct=0;
for(i=0;i<no;i++)
{
if(f[i-1].ct<f[i].at)
{
d=f[i].at-f[i-1].ct;
f[i].ct=f[i-1].ct+f[i].st+d;
f[i].tt=f[i].ct-f[i].at;
}
else
{
f[i].ct=f[i-1].ct+f[i].st;
f[i].tt=f[i].ct+f[i].at;
}
printf(“\nJob %d\n”,i+1);
printf(“Arrival time = %d\n”,f[i].at);
printf(“Service time = %d\n”,f[i].st);
printf(“Compilation time = %d\n”,f[i].ct);
printf(“Turnaround time = %d\n”,f[i].tt);
}
}
OUTPUT:
Enter the number of jobs 3
Enter the arrival time for job 1 15
Enter the service time for job 1 10
Enter the arrival time for job 2 25
Enter the service time for job 2 20
Enter the arrival time for job 3 35
Enter the service time for job 3 30
Job 1
Arrival time = 15
Service time = 10
Compilation time = 25
Turnaround time = 10
Job 2
Arrival time = 25
Service time = 20
Compilation time = 45
Turnaround time = 70
Job 3
Arrival time = 35
Service time = 30
Compilation time = 75
Turnaround time = 110
Comments
Post a Comment