82 Abhishek OS EXP4
82 Abhishek OS EXP4
Goykar
Software Used :-
Theory :-
executed first by the CPU. New process is executed only when the
current process is executed fully by the CPU.
Example :
0 0 2 2 2 0
1 1 6 8 7 1
2 2 4 12 10 6
3 3 9 21 18 9
Roll No: 82 Name: Abhishek A.
Goykar
4 6 12 33 29 17
(Gantt chart)
Advantages of FCFS
Disadvantages of FCFS
Once all the jobs get available in the ready queue, the algorithm
will behave as non-preemptive priority scheduling, which means the job
scheduled will run till the completion and no preemption will be done.
1. It is simple in use.
2. Important processes are never made to wait because of the
execution of less important processes.
Roll No: 82 Name: Abhishek A.
Goykar
Program Code :-
#include <stdio.h>
// Function to find the waiting time for all processes
int waitingtime(int proc[], int n,
int burst_time[], int wait_time[]) {
Roll No: 82 Name: Abhishek A.
Goykar
avgtime(proc, n, burst_time);
return 0;
}
Output :-
Roll No: 82 Name: Abhishek A.
Goykar
#include<stdio.h>
struct process
{
int WT,AT,BT,TAT,PT;
};
struct process a[10];
int main()
{
int n,temp[10],t,count=0,short_p;
float total_WT=0,total_TAT=0,Avg_WT,Avg_TAT;
printf("Enter the number of the process\n");
scanf("%d",&n);
printf("Enter the arrival time , burst time and priority of the
process\n");
printf("AT BT PT\n");
for(int i=0;i<n;i++)
{
scanf("%d%d%d",&a[i].AT,&a[i].BT,&a[i].PT);
// copying the burst time in
// a temp array fot futher use
temp[i]=a[i].BT;
Roll No: 82 Name: Abhishek A.
Goykar
}
// we initialize the burst time
// of a process with maximum
a[9].PT=10000;
for(t=0;count!=n;t++)
{
short_p=9;
for(int i=0;i<n;i++)
{
if(a[short_p].PT>a[i].PT && a[i].AT<=t && a[i].BT>0)
{
short_p=i;
}
}
a[short_p].BT=a[short_p].BT-1;
// if any process is completed
if(a[short_p].BT==0)
{
// one process is completed
// so count increases by 1
count++;
a[short_p].WT=t+1-a[short_p].AT-temp[short_p];
a[short_p].TAT=t+1-a[short_p].AT;
Roll No: 82 Name: Abhishek A.
Goykar
// total calculation
total_WT=total_WT+a[short_p].WT;
total_TAT=total_TAT+a[short_p].TAT;
}
}
Avg_WT=total_WT/n;
Avg_TAT=total_TAT/n;
// printing of the answer
printf("ID WT TAT\n");
for(int i=0;i<n;i++)
{
printf("%d %d\t%d\n",i+1,a[i].WT,a[i].TAT);
}
printf("Avg waiting time of the process is %f\n",Avg_WT);
printf("Avg turn around time of the process is %f\n",Avg_TAT);
return 0;
}
Output :-
Roll No: 82 Name: Abhishek A.
Goykar
Conclusion: