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

Exp. No. 1 - FCFS

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)
20 views3 pages

Exp. No. 1 - FCFS

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

EXPERIMENT NO.

CPU SCHEDULINGALGORITHMS

A). FIRST COME FIRST SERVE:

AIM: To write a C program to simulate the CPU scheduling algorithm First Come First
Serve (FCFS)

DESCRIPTION:

To calculate the average waiting time using the FCFS algorithm first the waiting time of the first
process is kept zero and the waiting time of the second process is the burst time of the first process
and the waiting time of the third process is the sum of the burst times of the first and the second
process and so on. After calculating all the waiting times the average waiting time is calculated as
the average of all the waiting times. FCFS mainly says first come first serve the algorithm which
came first will be served first.

ALGORITHM:

Step 1: Start the process


Step 2: Accept the number of processes in the ready Queue
Step 3: For each process in the ready Q, assign the process name and the burst time
Step 4: Set the waiting of the first process as ‗0‘and its burst time as its turnaround time
Step 5: for each process in the Ready Q calculate
a. Waiting time (n) = waiting time (n-1) + Burst time (n-1)
b. Turnaround time (n)= waiting time(n)+Burst time(n)
Step 6: Calculate
a. Average waiting time = Total waiting Time / Number of process
b. Average Turnaround time = Total Turnaround Time / Number of process

Step 7: Stop the process


SOURCE CODE:

#include <stdio.h>

int main() {
int bt[20], wt[20], tat[20], n;
float wtavg = 0, tatavg = 0;

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


scanf("%d", &n);

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


printf("Enter Burst Time for Process %d: ", i);
scanf("%d", &bt[i]);
}

wt[0] = 0;
tat[0] = bt[0];

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


wt[i] = wt[i - 1] + bt[i - 1];
tat[i] = tat[i - 1] + bt[i];
wtavg += wt[i];
tatavg += tat[i];
}

printf("\nPROCESS\tBURST TIME\tWAITING TIME\tTURNAROUND TIME\n");


for (int i = 0; i < n; i++) {
printf("P%d\t\t%d\t\t%d\t\t%d\n", i, bt[i], wt[i], tat[i]);
}

printf("Average Waiting Time: %.2f\n", wtavg / n);


printf("Average Turnaround Time: %.2f\n", tatavg / n);

return 0;
}
INPUT
Enter the number of processes -- 3
Enter Burst Time for Process 0 -- 24
Enter Burst Time for Process 1 -- 3
Enter Burst Time for Process 2 -- 3

OUTPUT
PROCESS BURST TIME WAITING TIME TURNAROUND
TIME
P0 24 0 24
P1 3 24 27
P2 3 27 30
Average Waiting Time-- 17.000000
Average Turnaround Time -- 27.000000

You might also like