0% found this document useful (0 votes)
8 views3 pages

FCFS Scheduling Algorithm Implementation

The document outlines the implementation of the First-Come, First-Served (FCFS) scheduling algorithm, detailing the steps to calculate waiting time and turnaround time for processes. It includes a C program that reads process IDs and burst times, computes waiting and turnaround times, and displays the results along with average times. A sample output demonstrates the program's functionality with three processes.

Uploaded by

mkgroshni
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
0% found this document useful (0 votes)
8 views3 pages

FCFS Scheduling Algorithm Implementation

The document outlines the implementation of the First-Come, First-Served (FCFS) scheduling algorithm, detailing the steps to calculate waiting time and turnaround time for processes. It includes a C program that reads process IDs and burst times, computes waiting and turnaround times, and displays the results along with average times. A sample output demonstrates the program's functionality with three processes.

Uploaded by

mkgroshni
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

FCFS

AIM

To implement the First-Come, First-Served (FCFS) scheduling algorithm, which calculates and displays
the waiting time and turnaround time for each process, as well as the average waiting time and
average turnaround time for all processes.

ALGORITHM

1. Input: Read the number of processes (n), Process IDs (pid[]), and burst times (bt[]).
2. Initialize: Set the waiting time for the first process as wt[0] = 0.
3. Calculate Waiting Time: For each process, calculate wt[i] = bt[i-1] + wt[i-1] for i >
0.
4. Calculate Turnaround Time: For each process, calculate TAT[i] = bt[i] + wt[i].
5. Display Results: Print process details and compute average waiting time and turnaround time.

PROGRAM:

#include <stdio.h>

int main() {

int pid[15], bt[15], wt[15], n;

printf("Enter the number of processes: ");

scanf("%d", &n);

printf("Enter process id of all the processes: ");

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

scanf("%d", &pid[i]);

printf("Enter burst time of all the processes: ");

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


scanf("%d", &bt[i]);

wt[0] = 0; // Waiting time for the first process is 0.

// Calculate waiting time for each process

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

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

printf("Process ID Burst Time Waiting Time Turnaround Time\n");

float twt = 0.0, tat = 0.0; // Total waiting time and turnaround time

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

// Print process ID, Burst Time, Waiting Time, Turnaround Time

printf("%d\t\t", pid[i]);

printf("%d\t\t", bt[i]);

printf("%d\t\t", wt[i]);

// Calculate and print Turnaround Time (TAT = BT + WT)

int tat_i = bt[i] + wt[i];

printf("%d\t\t", tat_i);

printf("\n");

// Add to total waiting time and turnaround time

twt += wt[i];

tat += tat_i;

}
// Calculate and print average waiting time and average turnaround time

float awt = twt / n; // Average Waiting Time

float att = tat / n; // Average Turnaround Time

printf("Avg. waiting time = %.2f\n", awt);

printf("Avg. turnaround time = %.2f\n", att);

return 0;

RESULT:
Thus the program was verified and executed successfully.

SAMPLE OUTPUT:

Enter the number of processes: 3

Enter process id of all the processes: 1 2 3

Enter burst time of all the processes: 6 7 8

Process ID Burst Time Waiting Time Turnaround Time

1 6 0 6

2 7 6 13

3 8 13 21

Avg. waiting time = 6.33

Avg. turnaround time = 13.33Average Turnaround Time: 13.33

You might also like