DESCRIPTION:-
Scheduling of processes/work is done to finish the work on time.
Below are different times with respect to a process.
Arrival Time: Time at which the process arrives in the ready queue.
Completion Time: Time at which process completes its execution.
Burst Time: Time required by a process for CPU execution.
Turn Around Time: Time Difference between completion time and arrival time.
Turn Around Time=Completion Time-Arrival Time
Waiting Time(W.T): Time Difference between turn around time and burst time.
Waiting Time=Turn Around Time-Burst Time.
FCFS Scheduling-
In FCFS Scheduling,
The process which arrives first in the ready queue is firstly assigned the CPU.
In case of a tie,process with smaller process id is executed first.
It is always non-preemptive in nature.
CODE:-
#include<stdio.h>
int main()
{
int at[10],at2[10],bt[100],ex[100],seq[100],re[100],wt[100],tat[100];
int n,i,j,start,pos,max=0,min,idle=0,k=0;
float av1=0,av2=0;
printf("*****INPUT*****\n");
printf("Enter number of process\n");
scanf("%d",&n);
printf("Enter arrival time for processess\n");
for(i=0;i<n;i++)
{
scanf("%d",&at[i]);
at2[i]=at[i];
}
printf("Enter burst time for processess\n");
for(i=0;i<n;i++)
{
scanf("%d",&bt[i]);
}
start=at[0];
for(i=1;i<n;i++)
{
if(start>at[i])
{
start=at[i];
}
}
printf("*****OUTPUT*****\n");
printf("Sequence of execution is\n");
for(i=0;i<n;i++)
{
if(max<at[i])
{
max=at[i];
}
}
max=max+1;
for(i=0;i<n;i++,k++)
{ min=max;
for(j=0;j<n;j++){
if(at[j]!=-1)
{
if(at[j]<min)
{
min=at[j];
pos=j;
}
}
}
printf("[P%d] ",pos);
seq[k]=pos;
if(start<at[pos]){
re[pos]=start;
idle+=at[pos]-start;
start=at[pos];
start+=bt[pos];
at[pos]=-1;
ex[pos]=start;
}
else{
re[pos]=start;
start+=bt[pos];
at[pos]=-1;
ex[pos]=start;
}
}
printf("\n");
for(i=0;i<n;i++)
{
tat[i]=ex[i]-at2[i];
wt[i]=tat[i]-bt[i];
}
printf("Process Arrival-time(s) Burst-time(s) Waiting-time(s) Turnaround-time(s)\n");
for(i=0;i<n;i++)
{
printf("P%d %d %d %d %d\n",i,at2[i],bt[i],wt[i],tat[i]);
}
for(i=0;i<n;i++)
{
av1+=tat[i];
av2+=wt[i];
}
printf("Average waiting time(s) %f\nAverage turnaroundtime(s) %f\nCPU idle time(s)%d\n",av2/n,av1/n,idle);
}
OUTPUT:-
*****INPUT*****
Enter number of process
5
Enter arrival time for processess
3 5 0 5 4
Enter burst time for processess
4 3 2 1 3
*****OUTPUT*****
Sequence of execution is
[P2] [P0] [P4] [P1] [P3]
Process Arrival-time(s) Burst-time(s) Waiting-time(s) Turnaround-time(s)
P0 3 4 0 4
P1 5 3 5 8
P2 0 2 0 2
P3 5 1 8 9
P4 4 3 3 6
Average waiting time(s) 3.200000
Average turn around time(s) 5.800000
CPU idle time(s)1
Process returned 0 (0x0) execution time : 35.057 s
Press any key to continue.
Comments