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

First Come First Served Scheduling

1. This document describes an algorithm for implementing First Come First Served (FCFS) scheduling using C language constructs. 2. In FCFS scheduling, processes that request the CPU first are allocated the CPU first and are placed in a first-in-first-out queue. 3. The algorithm prompts the user to input process details like name, burst time, and arrival time, calculates waiting times and turnaround times, and displays them along with an average and Gantt chart.

Uploaded by

prasras
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
517 views3 pages

First Come First Served Scheduling

1. This document describes an algorithm for implementing First Come First Served (FCFS) scheduling using C language constructs. 2. In FCFS scheduling, processes that request the CPU first are allocated the CPU first and are placed in a first-in-first-out queue. 3. The algorithm prompts the user to input process details like name, burst time, and arrival time, calculates waiting times and turnaround times, and displays them along with an average and Gantt chart.

Uploaded by

prasras
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

1

First Come First Served Scheduling

Aim:
To implement the FCFS Problem using C language constructs.

Objective:
1. This is one of the very brute force algorithm. A process that requests for the CPU first
is allocated the CPU first. Hence, the name first come first serve.
2. The FCFS algorithm is implemented by using first-in-first-out (FIFO) queue structure
for the ready queue.
3. When a process joins the ready queue its PCB is linked to the tail of the FIFO queue.
4. When the CPU is idle, the process at the head of the FIFO queue is allocated the CPU
and deleted from the queue.
5. To implement the queue using arrays.

Algorithm:
1. The arrays for processes, waiting time, turnaround time, burst time, and arrival time are
pname[ ][ ], wt[ ], tt[ ], bt[ ], at[ ] respectively.
2. The user is prompted for NAME, BURST TIME, and ARRIVAL TIME using printf() and
values for the arrays are accepted using scanf( ) functions.
3. The process at the head is deleted from the queue and is assigned to a temp variable.
4. The total waiting time, turn around time and their average is processed and printed using
printf( ) function inside a for( ) loop.
5. The GANT CHART is displayed using printf( ) function and the various formatting
escape sequences.

Program:
#include<stdio.h>
#include<conio.h>
#include<string.h>

void main( )
{
float avgwt, avgtt;
char pname[10][10];
int wt[10], tt[10], bt[10], at[10], t, q, I, n, sum=0, ttime, j, ss=0;
printf(“\n\nEnter the number of processes:”);
scanf(“%d”, &n);
printf(“\n\nEnter the NAME, BURST TIME and ARRIVAL TIME of the process:”);
for(i=0; i<n; i++)
{
2

printf(“\n\n NAME:”);
scanf(“%s”, &pname[i]);
printf(“\n\n BURST TIME:”);
scanf(“%d”, &bt[i]);
printf(“\n\n ARRIVAL TIME:”);
scanf(“%d”, &at[i]);
}
for(i=0; i<n; i++)
for(j=i+1; j<n; j++)
{
if(at[i] > at[j])
{
t = at[i];
at[i] = at[j];
at[j] = t;
q = bt[i];
bt[i] = bt[j];
bt[j] = q;
strcpy(c[i], pname[i]);
strcpy(pname[i], pname[j]);
strcpy(pname[j], c[i]);
}
}
wt[0] = 0;
for(i=0; i<n; i++)
{
wt[i+1] = wt[i] + bt[i];
sum = sum + (wt[i+1] – at[i]);
tt[i] = ss + bt[i];
}
avgwt = (float) wt[i]/n;
avgtt = (float) sum/n;
printf(“\n\nAverage Waiting Time = %f”, avgwt);
printf(“\n\nAverage Turn-around Time = %f”, avgtt);
printf(“\n\n GANTT CHART\N”);
for(i=0; i<n; i++)
{
printf(“|\t%s\t”, pname[i]);
}
printf(“\n”);
for(i=0; i<n; i++)
{
3

printf(“%d\t\t”, wt[i]);
}
printf(“%d\n”, ss);
printf(“\n”);
getch( );
}

Output:
Enter the number of processes: 3
Enter the NAME, BURST TIME and ARRIVAL TIME of the process:
NAME: P1
BURST TIME: 24
ARRIVAL TIME: 0
NAME: P2
BURST TIME: 3
ARRIVAL TIME: 0
NAME: P3
BURST TIME: 3
ARRIVAL TIME: 0
Average Waiting Time = 10.000000
Average Turn-around Time = 27.000000
GANTT CHART
| P1 | P2 | P3
0| 24 | 3 | 3

You might also like