31/03/2023

FCFS Scheduling Program in C++ With Arrival Time And Gantt Chart

First Come First Served (FCFS) is a Non-Preemptive scheduling algorithm. FCFS follow the FIFO (First In First Out) rules which means when a process comes to the CPU for execution. The CPU executes the process without checking anything like in a primitive scheduling algorithm. In other words. The First process will be executed either because the execution time of the first process is higher than others.

FCFS Scheduling Program in C++ With Arrival Time And Gantt Chart

The first process runs another process should wait for its turn. Below is the Brief description or Q&A of the FCFS Non-Preemptive scheduling algorithm.

FCFS Scheduling Program in C++ With Arrival Time And Gantt Chart


#include <stdio.h>
#include <string.h>

int strToint(char[]);

int main()
{
	/*FCFS Scheduling Program in C++ With Arrival Time And Gantt Chart*/

	cout << "=====================================";
	cout << "\nVisit - www.programmingwithbasics.com";
	cout << "\n=====================================";

	while (1)
	{
		char str[10];
		int intNum;

		printf("\n\nEnter Integer Number: ");
		scanf("%s", str);

		intNum = strToint(str);

		if (intNum == 0)
		{
			printf("\nEnter The Number Not String\n\n");
		}
		else
		{
			printf("\n\nEquivalent Integer Value: %d", intNum);
		}
	}

	return 0;
}

int strToint(char str[])
{
	int i = 0, sum = 0;

	while (str[i] != '\0')
	{
		if (str[i] < 48 || str[i] > 57)
		{
			printf("\n\nCan't Convert Into Integer");
			return 0;
		}
		else
		{
			sum = sum *10 + (str[i] - 48);
			i++;
		}
	}

	return sum;

}

return sum;

}

First Come First Serve Scheduling


  • What is the First Come First Serve (FCFS) Scheduling?
  • How to Calculate Turn-Around Time?
  • How to Calculate Waiting Time?
  • First Come First Serve Example

What is the First Come First Served (FCFS) Scheduling?



First Come First Served (FCFS) is a Non-Preemptive scheduling algorithm for process execution in an operating system and easy to understand and has poor performance (waiting time is higher), If the first process takes more time for execution than until finish first process rest of the process has to wait.

How to Calculate Turn-Around Time?


Turn Around Time = Completion Time – Arrival Time

With the help of this formula, we can calculate a Turn Around Time of all processes in Queue.

How to Calculate Waiting Time?.


Waiting Time = Turn Around Time – Burst Time

This formula is used for calculating the waiting time for the rest of the process.

FCFS Example


We are taking 5 processes whose CBT, or Burst Time Is 4, 9, 8, 3, and 7 respectively and the output is given below.

Enter The Total Number of Processes: 5

Enter CBT of Process:
4
9
8
3
7

=======================
Gantt. Chart
=======================
[P1] [P2] [P3] [P4] [P5]
--------------------------------------

0 4 13 21 24

==================================
Process CBT Waiting Time Turn Around Time
==================================

[p1] 4 0 4
[p2] 9 4 13
[p3] 8 13 21
[p4] 3 21 24
[p5] 7 24 31

Average Awating Time: 12.4

Average Turn Around Time: 18.6

The Output of FCFS Scheduling Program With Arrival Time


The Output of FCFS Scheduling Program With Arrival Time

Similar to FCFS Scheduling

Previous Post
Next Post

post written by:

Hi, I’m Ghanendra Yadav, SEO Expert, Professional Blogger, Programmer, and UI Developer. Get a Solution of More Than 500+ Programming Problems, and Practice All Programs in C, C++, and Java Languages. Get a Competitive Website Solution also Ie. Hackerrank Solutions and Geeksforgeeks Solutions. If You Are Interested to Learn a C Programming Language and You Don't Have Experience in Any Programming, You Should Start with a C Programming Language, Read: List of Format Specifiers in C.
Follow Me

0 Comments: