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

exp_3 operating sys

The document provides a C program that implements the First-Come, First-Served (FCFS) CPU scheduling algorithm. It includes functions to calculate waiting time, turnaround time, and average times for a set of processes based on their burst times. The program prompts the user to input the number of processes and their respective burst times, then displays the scheduling details and average times.

Uploaded by

Vivek Kumar
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)
0 views3 pages

exp_3 operating sys

The document provides a C program that implements the First-Come, First-Served (FCFS) CPU scheduling algorithm. It includes functions to calculate waiting time, turnaround time, and average times for a set of processes based on their burst times. The program prompts the user to input the number of processes and their respective burst times, then displays the scheduling details and average times.

Uploaded by

Vivek Kumar
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

EXPERINMENT-3

AIM:- write a program to implement FCFS CPU scheduling algorithm in C.


# code:-
#include <stdio.h>

// Function to find the waiting time for all processes


void findWaitingTime(int processes[], int n, int bt[], int wt[]) {
wt[0] = 0; // waiting time for first process is 0

// calculating waiting time


for (int i = 1; i < n; i++)
wt[i] = bt[i - 1] + wt[i - 1];
}

// Function to calculate turn around time


void findTurnAroundTime(int processes[], int n, int bt[], int wt[], int tat[]) {
// calculating turnaround time by adding bt[i] + wt[i]
for (int i = 0; i < n; i++)
tat[i] = bt[i] + wt[i];
}

// Function to calculate average time


void findAvgTime(int processes[], int n, int bt[]) {
int wt[n], tat[n], total_wt = 0, total_tat = 0;

// Function to find waiting time of all processes


findWaitingTime(processes, n, bt, wt);

// Function to find turn around time for all processes

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

// Display processes along with all details


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

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


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

printf("\nAverage waiting time = %.2f", (float)total_wt / n);


printf("\nAverage turn around time = %.2f\n", (float)total_tat / n);
}

// Main function
int main() {
int n;
printf("Enter number of processes: ");
scanf("%d", &n);

int processes[n], burst_time[n];


for (int i = 0; i < n; i++) {
processes[i] = i + 1;
printf("Enter burst time for process %d: ", i + 1);
scanf("%d", &burst_time[i]);
}

findAvgTime(processes, n, burst_time);

VIVEKANAND
2300321540212
return 0;
}

Output:-

VIVEKANAND
2300321540212

You might also like