0% found this document useful (0 votes)
8 views

FCFS scheduling algorithm

Uploaded by

Web Engineer
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views

FCFS scheduling algorithm

Uploaded by

Web Engineer
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

FCFS scheduling algorithm

The First Come First Serve (FCFS) CPU scheduling algorithm is the simplest type of
scheduling algorithm. In FCFS, the process that arrives first is executed first, without considering
the priority or the burst time (execution time) of the process. It's similar to standing in a queue at
a bank where the first person to arrive is the first to be served.

How FCFS Works:

• Non-preemptive: Once the CPU starts executing a process, it will finish it before moving
to the next process.
• Queue-based: Processes are handled in the order they arrive.

Steps of FCFS:

1. When processes arrive, they are placed in a queue.


2. The CPU starts executing the process that has been waiting the longest (i.e., the one at the
front of the queue).
3. After completing the process, the CPU moves to the next one in line.

Example of FCFS:

Let's say there are 3 processes arriving at different times:

Process Arrival Time (ms) Burst Time (ms)


P1 0 5
P2 1 3
P3 2 8

Step-by-step Execution:

1. P1 arrives at time 0 and starts executing since it is the first to arrive. It finishes after 5ms.
2. P2 arrives at time 1, but it must wait until P1 finishes. P2 starts at time 5 and runs for
3ms, finishing at time 8.
3. P3 arrives at time 2, but it must wait for both P1 and P2 to finish. P3 starts at time 8 and
runs for 8ms, finishing at time 16.

Gantt Chart:

| P1 | P2 | P3 |
0 5 8 16

Important Metrics:
• Turnaround Time = Completion Time - Arrival Time
o P1: 5 - 0 = 5 ms
o P2: 8 - 1 = 7 ms
o P3: 16 - 2 = 14 ms
• Waiting Time = Turnaround Time - Burst Time
o P1: 5 - 5 = 0 ms
o P2: 7 - 3 = 4 ms
o P3: 14 - 8 = 6 ms

Pros of FCFS:

• Simple to understand and implement.


• Fair: Every process gets a chance based on its arrival.

Cons of FCFS:

• Non-preemptive: If a process with a long burst time arrives first, other processes will
have to wait (leading to poor performance for short tasks).
• Convoy Effect: Shorter processes may get delayed by longer processes.

In this example, P3 had to wait a long time because P1 and P2 arrived earlier. FCFS is not ideal
for time-critical processes but works fine when all processes have similar burst times.

You might also like