0% found this document useful (0 votes)
58 views4 pages

FCFS Scheduling Program in C

1. The document describes a program to implement the First Come First Serve (FCFS) scheduling algorithm. 2. The algorithm selects the first process that arrived in the ready queue, calculates waiting times and turnaround times for each process, and displays the average waiting time and average turnaround time. 3. The program takes input of process names, burst times, and arrival times, sorts by arrival time, calculates waiting times and turnaround times for each process, and outputs performance metrics and a Gantt chart.

Uploaded by

San Dip
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)
58 views4 pages

FCFS Scheduling Program in C

1. The document describes a program to implement the First Come First Serve (FCFS) scheduling algorithm. 2. The algorithm selects the first process that arrived in the ready queue, calculates waiting times and turnaround times for each process, and displays the average waiting time and average turnaround time. 3. The program takes input of process names, burst times, and arrival times, sorts by arrival time, calculates waiting times and turnaround times for each process, and outputs performance metrics and a Gantt chart.

Uploaded by

San Dip
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

Operating System

EX NO: 7

Date:

Write a program for implementing the FCFS Scheduling algorithm

AIM: To write a program for implementing FCFS scheduling algorithm.

ALGORITHM:
1. Start the process.
2. Declare the array size.
3. Get the number of elements to be inserted.
4. Select the process that first arrived in the ready queue
5. Make the average waiting the length of next process.
6. Start with the first process from it’s selection as above and let other process to
be in queue.
7. Calculate the total number of burst time.
8. Display the values.
9. Stop the process.

PROGRAM:

#include<stdio.h>

main()

float avgwt,avgtt;

char pname[10][10],c[10][10];

int wt[10],tt[10],bt[10],at[10],t,q,i,n,sum=0,sbt=0,ttime,j,ss=0;

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

scanf("%d",&n);

printf("\n\n Enter the NAME , BURST TIME and ARRIVAL TIME of the
process");

Nepathya College Laboratory


Operating System

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

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]);

Nepathya College Laboratory


Operating System

wt[0]=0;

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

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

sum=sum+(wt[i]-at[i]);

sbt=sbt+(wt[i+1]-at[i]);

tt[i]=wt[i]+bt[i];

ss=ss+bt[i];

avgwt=(float) sum/n;

avgtt=(float)sbt/n;

printf("\n\n Average waiting time = %f",avgwt);

printf("\n\n Average 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++)

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

printf("%d\n",ss);

printf("\n");

Nepathya College Laboratory


Operating System

OUTPUT:

[root@localhost ~]# ./[Link]


Enter the number of processes: 4
Enter the NAME , BURST TIME and ARRIVAL TIME of the process
NAME : p1
BURST TIME : 4
ARRIVAL TIME : 0
NAME : p2
BURST TIME : 9
ARRIVAL TIME : 2
NAME : p3
BURST TIME : 8
ARRIVAL TIME : 4
NAME : p4
BURST TIME : 3
ARRIVAL TIME : 3

Average waiting time = 6.000000


Average turn-around time = 12.000000
GANTT CHART
| p1 | p2 | p4 | p3
0 4 13 16 24

RESULT:
Thus the program for implementing FCFs scheduling algorithm was written and
successfully executed.

Nepathya College Laboratory

Common questions

Powered by AI

The Gantt chart provides a visual representation of the scheduling of processes over time within the FCFS framework . It shows the order of process execution and the specific timing of each process's start and end times. This visualization aids in understanding which processes are waiting and when they are executed, highlighting potential inefficiencies such as the convoy effect, where longer processes block shorter ones.

The FCFS scheduling algorithm fails to address process priority as it operates based purely on the arrival time of processes . It lacks mechanisms for prioritizing urgent or more critical processes that may need quicker execution, treating all processes equally regardless of their importance or urgency, which can be problematic in systems requiring responsive task prioritization.

The benefits of using the FCFS scheduling algorithm include its simplicity and fairness, as each process gets executed in the order it arrives . However, drawbacks include potential inefficiency due to the possibility of long wait times, especially in the case of a large burst time for a single process (convoy effect), and lack of priority handling or preemption which can hinder performance and cause delays in critical tasks.

The implementation first collects process names, burst times, and arrival times from user input . It then sorts processes by arrival time, ensuring that those which arrive earlier are processed first. This method calculates wait times by iterating over the sorted list, adding burst times sequentially. This sorting and subsequent calculations minimize wait times for earlier processes but can lead to longer wait times for those arriving later in the sequence, demonstrating the inherent disadvantage of FCFS where turnaround time can vary widely depending on initial arrival times.

User input is crucial in determining the algorithm's effectiveness since the process names, burst times, and arrival times directly influence the order of execution and calculation of waiting and turnaround times . Inaccurate or inefficient input, such as incorrectly entered times, can lead to erroneous calculations and thus undermine the scheduling effectiveness, highlighting the necessity for accurate and thoughtful input data.

The FCFS scheduling algorithm involves the following key steps: starting the process, declaring the array size, getting the number of elements to be inserted, selecting the process that first arrived in the ready queue, computing the average waiting time for the next process, starting with the first process and allowing others to queue, calculating the total burst time, and displaying the values . The sequence is important to ensure that processes are executed in the order they arrive, which is the essence of the FCFS principle, leading to predictable scheduling behavior.

In the FCFS scheduling algorithm, average waiting time is calculated by summing the waiting times of all processes and dividing by the number of processes . Specifically, the wait time for an individual process is computed as the sum of burst times of all previous processes minus the arrival time of the current process. This metric signifies the efficiency of the scheduling process from a queue perspective, with higher average waiting times indicating less optimal scheduling.

In a real-time system with dynamic process arrivals, the FCFS algorithm faces challenges such as handling unpredictable and continuous process flows, ensuring low latency for urgent tasks, and avoiding delays seen with static queues . Adapting FCFS to such a dynamic environment requires mechanisms to temporarily reorder processes based on changing conditions and incorporate elements of preemptive scheduling to improve responsiveness and efficiency.

Sorting by arrival time ensures that processes are executed in the precise order in which they arrive, which is central to FCFS scheduling . While this upholds the FCFS principle, it leads to possible inefficiencies where processes with longer burst times can significantly delay subsequent queued processes. This sorting affects the overall execution time by potentially increasing waiting times if a high-burst-time process arrives earlier.

The FCFS scheduling program uses several computational variables such as 'wt' for waiting times, 'tt' for turnaround times, 'bt' for burst times, and 'at' for arrival times . The relationship between these variables involves calculating the waiting times based on arrival and burst times, and then determining the turnaround time as the sum of waiting time and burst time for each process. This interaction anchors the scheduling and execution sequence.

You might also like