FCFS

FCFS Scheduling Algorithm: What is, Example Program

What exactly is the First Come, First Served Method of service?
A scheduling algorithm used by operating systems to automatically execute queued requests and processes in the order in which they are received is known as First Come First Serve (FCFS). It is the most straightforward and straightforward CPU scheduling algorithm. In this type of algorithm, the processes that request the CPU allocation first are the ones that receive the CPU allocation first. This is accomplished through the use of a first-in, first-out queue. First Come, First Served (FCFS) is the full form of the phrase.

As soon as the process enters the ready queue, its PCB (Process Control Block) is linked to the tail of the queue, and when the CPU becomes available, it should be assigned to the process at the beginning of the queue, as shown in the following diagram.

In this operating system tutorial, you will learn how to do the following:

Characteristics of FCFS method

Characteristics of the FCFS procedure
Preemptive and non-preemptive scheduling algorithms are supported by this algorithm.
Jobs are always executed on a first-come, first-served basis, regardless of their priority.
It is simple to put into action and to use.
Overall, the performance of this method is poor, and the overall wait time is quite long.

Example of FCFS scheduling

Scheduling in the FCFS as an illustration
The purchase of a movie ticket at the ticket counter is an example of the FCFS method in action in real life. In this scheduling algorithm, a person is served in the order in which they are placed in the queue. The person who arrives first in the queue purchases the first ticket, followed by the next one, and so on. This will continue until the ticket is purchased by the last person in the queue in front of you. The CPU process operates similarly to that of the GPU process when using this algorithm.

How does FCFS Works? Calculating Average Waiting Time

Here’s an example of five processes that arrive at different times on the same day. Each process has a unique burst time that can be observed.

Process Arrival time Burst time Process Burst time
P1 6 2 \sP2 2 5 \sP3 8 1 \sP4 3 0 \sP5 4 4
These processes are handled in the following ways, thanks to the FCFS scheduling algorithm.

Step 0) The process starts with P4, which has an arrival time of 0 minutes.

Step 1) P3 arrives at the specified time. P4 is still in the middle of its execution. As a result, P3 is placed in a queue.

Process Arrival time Burst time Process Burst time
P1 6 2 \sP2 2 5 \sP3 8 1 \sP4 3 0 \sP5 4 4

The second step occurs at time=2 when P1 arrives and is placed in the queue.

Process Arrival time Burst time Process Burst time
P1 6 2 \sP2 2 5 \sP3 8 1 \sP4 3 0 \sP5 4 4

Step 3) The P4 process completes its execution at the third time step.

In the fourth step, at time=4, P3, which is first in the queue, begins to execute.

Process Arrival time Burst time Process Burst time
P1 6 2 \sP2 2 5 \sP3 8 1 \sP4 3 0 \sP5 4 4

Step 5) When time =5 arrives, P2 is received and placed in a queue.

Process Arrival time Burst time Process Burst time
P1 6 2 \sP2 2 5 \sP3 8 1 \sP4 3 0 \sP5 4 4

Step 6) P3 completes its execution at the eleventh minute.

Step 7) P1 begins execution at the eleventh minute of the timer. It has a burst time of six seconds. It completes its execution at the 17th time interval.

Step 8) At time=17, the P5 program begins to run. It has a burst time of four seconds. It completes its execution at the count of twenty-one.

Step 9) P2 begins execution at the count of twenty-one. It has a burst time of two seconds. It completes its execution at the 23rd time interval.

Step 10) For this example, let’s calculate the average waiting time.

Waiting time equals the difference between the start time and the arrival time P4 = 0-0 = 0.

P3 = 3-1 = 2 = P3 = 3-1 = 2

PI = 11-2 = 9 is a prime number.

P5 = 17-4 = 13 (P5 = 17-4 = 13)

The second number is P2= 21-5= 16.

Waiting Time on the Average

40/5= 8 = 40/5= 8

Advantages of FCFS

FCFS has a number of advantages.
The following are some of the advantages and disadvantages of using the FCFS scheduling algorithm:

The most basic form of a CPU scheduling algorithm is as follows:
Programming is simple.
The first-come, the first-served policy applies.
FCFS has several disadvantages.
The following are some disadvantages and drawbacks of using the FCFS scheduling algorithm:

Disadvantages of FCFS

It is a Non-Preemptive CPU scheduling algorithm, which means that once a process has been allocated to a CPU, the CPU will not be released until the process has completed its execution.
The average waiting time is extremely long.
Short processes that are at the back of the queue must wait for the long process at the front of the queue to finish before they can proceed.
When it comes to time-sharing systems, this is not the best technique.
FCFS is not very efficient because it is so straightforward.

Summary:

Definition: It is a scheduling algorithm for operating systems that automatically executes queued requests and processes them in the order in which they are received.
Preemptive and non-preemptive scheduling algorithms are supported by this algorithm.
FCFS is an abbreviation for First Come, First Served.
The purchase of a movie ticket at the ticket counter is an example of the FCFS method in action in real life.
It is the simplest possible implementation of a CPU scheduling algorithm.
It is a Non-Preemptive CPU scheduling algorithm, which means that once a process has been allocated to a CPU, the CPU will not be released until the process has completed its execution.