100% found this document useful (2 votes)
621 views

Lap No-07 - Implementation of FCFS Scheduling Algorithm

The document describes the implementation of the First Come First Served (FCFS) CPU scheduling algorithm. It defines FCFS as a non-preemptive algorithm that processes jobs in the order of arrival, with the first arriving job processed first. A C program is presented that takes job burst times as input, calculates waiting times and turnaround times for each job, and outputs the average waiting and turnaround times.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (2 votes)
621 views

Lap No-07 - Implementation of FCFS Scheduling Algorithm

The document describes the implementation of the First Come First Served (FCFS) CPU scheduling algorithm. It defines FCFS as a non-preemptive algorithm that processes jobs in the order of arrival, with the first arriving job processed first. A C program is presented that takes job burst times as input, calculates waiting times and turnaround times for each job, and outputs the average waiting and turnaround times.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Lab Report No.

07

Lab Report Name: Implementation of FCFS Scheduling algorithm .

Objectives:
i. What is FCFS Scheduling algorithm.
ii. How to implementation in C
Theory:
First Come First Served (FCFS) is a Non-Preemptive scheduling algorithm. FIFO (First In First
Out) strategy assigns priority to process in the order in which they request the processor. The
process that requests the CPU first is allocated the CPU first. This is easily implemented with a
FIFO queue for managing the tasks. As the process come in, they are put at the end of the queue. As
the CPU finishes each task, it removes it from the start of the queue and heads on to the next task.

Example:

C program for implementing FCFS:

#include<stdio.h>
void findWaitingTime(int processes[], int n,int bt[], int wt[])
{

wt[0] = 0;

for (int i = 1; i < n ; i++ )


wt[i] = bt[i-1] + wt[i-1] ;
}

void findTurnAroundTime( int processes[], int n,int bt[], int wt[], int tat[])
{

for (int i = 0; i < n ; i++)


tat[i] = bt[i] + wt[i];
}

void findavgTime( int processes[], int n, int bt[])


{
int wt[n], tat[n], total_wt = 0, total_tat = 0;

findWaitingTime(processes, n, bt, wt);

findTurnAroundTime(processes, n, bt, wt, tat);

printf("\n\nProcesses Burst time Waiting time Turn around time\n");

for (int i=0; i<n; i++)


{
total_wt = total_wt + wt[i];
total_tat = total_tat + tat[i];
printf(" %d %d %d %d\n",(i+1), bt[i],wt[i],tat[i]);

}
double s=(float)total_wt / (float)n;
double t=(float)total_tat / (float)n;

printf("\nAverage waiting time = %f\n",s);


printf("\n");
printf("Average turn around time = %f \n",t);
}

int main()
{
int n;
printf("Enter the number of process : ");
scanf("%d",&n);

int processes[n],burst_time[n];
int i=0;
while(i<n){
//for(int i =0; i<n; i++){
printf("Enter process %d bust time : ",i+1);
processes[i] = i+1;

scanf("%d",&burst_time[i]);
i++;
}

findavgTime(processes, n, burst_time);
return 0;
}

output:

You might also like