Operating System FCFS Scheduling Algorithm

FCFS scheduling algorithm is widely used in various operating systems due to its simplicity and fairness. It follows a simple rule – “first come, first served”. When a process enters the ready queue, it is assigned the CPU time immediately if it is available. This means that the process that arrives first is given the highest priority and is executed first. Only when this process completes or is blocked, the next process in the queue is executed.

One of the advantages of FCFS scheduling is its simplicity. The algorithm does not require any complex calculations or heuristics to determine the order in which processes should be executed. It follows a straightforward approach of executing processes in the order of their arrival. This simplicity makes it easy to implement and understand, even for novice programmers.

However, FCFS scheduling algorithm also has its limitations. One major drawback is its lack of consideration for the process execution time. In FCFS, if a long-running process arrives first, it can monopolize the CPU, causing other processes to wait for a significant amount of time. This can lead to poor overall system performance and increased waiting times for processes with shorter execution times.

Another limitation of FCFS is its inability to handle priority-based scheduling. Since it does not consider the priority of processes, a high-priority process may have to wait for a long time if it arrives after a low-priority process. This can lead to inefficient utilization of system resources and may not be ideal for time-critical applications.

Despite its limitations, FCFS scheduling algorithm is still widely used in certain scenarios. For example, in batch processing systems where all processes have similar execution times and priority is not a concern, FCFS can be an efficient choice. It ensures fairness by executing processes in the order they arrive, and it is relatively easy to implement and manage.

In conclusion, the FCFS scheduling algorithm is a simple and straightforward approach to process scheduling. It assigns CPU time to processes based on their arrival order, making it fair and easy to implement. However, it may not be suitable for all scenarios, especially when priority or process execution times are important factors to consider.

Suppose we have three processes: P1, P2, and P3. The arrival time and burst time for each process are as follows:

ProcessArrival TimeBurst Time
P105
P213
P324

Using the FCFS scheduling algorithm, the processes will be executed in the order they arrive in the ready queue. The Gantt chart representation of the execution is as follows:

As shown in the Gantt chart, the first process P1 arrives at time 0 and gets the CPU. It executes for 5 units of time and completes. Then, the next process P2 arrives at time 1 and gets the CPU. It executes for 3 units of time and completes. Finally, the last process P3 arrives at time 2 and gets the CPU. It executes for 4 units of time and completes.

The average waiting time for the three processes can be calculated as follows:

Waiting Time for P1 = 0

Waiting Time for P2 = 5 (arrival time of P2 – completion time of P1)

Waiting Time for P3 = 8 (arrival time of P3 – completion time of P2)

Average Waiting Time = (0 + 5 + 8) / 3 = 4.33 units of time

Thus, the average waiting time for the given set of processes using the FCFS scheduling algorithm is 4.33 units of time.

It is important to note that the FCFS scheduling algorithm is non-preemptive, meaning once a process gets the CPU, it will continue to execute until it completes or is blocked by an I/O request. This can lead to poor performance if there are long-running processes that arrive early in the ready queue, as they will block the execution of subsequent processes.

In conclusion, the FCFS scheduling algorithm works by allocating the CPU to the first process in the ready queue and continuing execution until it completes or is blocked. It is a simple and easy-to-understand algorithm, but it may not always be the most efficient choice, especially in scenarios with long-running processes.

Example of FCFS Scheduling Algorithm

Consider the following set of processes with their arrival times and burst times:

ProcessArrival TimeBurst Time
P108
P214
P3210

Using the FCFS scheduling algorithm, the execution order of the processes would be as follows:

  1. Process P1 arrives at time 0 and gets the CPU. It executes for 8 units of time.
  2. Process P2 arrives at time 1 but has to wait until P1 completes. It executes for 4 units of time.
  3. Process P3 arrives at time 2 but has to wait until both P1 and P2 complete. It executes for 10 units of time.

The average waiting time and turnaround time for the above example can be calculated as follows:

To calculate the average waiting time, we sum up the waiting times of all the processes and divide by the number of processes. In this case, the waiting times are as follows:

  • Process P1: 0 units
  • Process P2: 7 units (waiting time = burst time of P1)
  • Process P3: 11 units (waiting time = burst time of P1 + burst time of P2)

Therefore, the total waiting time is 0 + 7 + 11 = 18 units. Since there are 3 processes, the average waiting time is 18 / 3 = 6 units.

To calculate the average turnaround time, we sum up the turnaround times of all the processes and divide by the number of processes. The turnaround time is the sum of the burst time and waiting time for each process. In this case, the turnaround times are as follows:

  • Process P1: 8 units (turnaround time = burst time of P1 + waiting time of P1)
  • Process P2: 11 units (turnaround time = burst time of P2 + waiting time of P2)
  • Process P3: 21 units (turnaround time = burst time of P3 + waiting time of P3)

Therefore, the total turnaround time is 8 + 11 + 21 = 40 units. Since there are 3 processes, the average turnaround time is 40 / 3 = 13.33 units.

Thus, in this example, the average waiting time is 6 units and the average turnaround time is 13.33 units. These values can be used to evaluate the performance of the FCFS scheduling algorithm in this particular scenario.

Calculating Average Waiting Time and Turnaround Time

To calculate the average waiting time and turnaround time, we need to analyze the waiting and turnaround times of each process in a given system. Let’s consider an example with three processes: P1, P2, and P3.

For P1, the waiting time is 0, as it starts executing immediately. The turnaround time is equal to the burst time of P1, which is 8 units of time.

For P2, the waiting time is the burst time of P1, which is 8 units of time. The turnaround time is the sum of P1’s burst time and P2’s burst time, which is 12 units of time.

For P3, the waiting time is the sum of P1’s burst time and P2’s burst time, which is 12 units of time. The turnaround time is the sum of P1’s burst time, P2’s burst time, and P3’s burst time, which is 22 units of time.

Now, let’s calculate the total waiting time. We add up the waiting times of all processes: 0 + 8 + 12 = 20 units of time. To find the average waiting time, we divide the total waiting time by the number of processes, which is 3. Therefore, the average waiting time is 20 / 3 = 6.67 units of time.

Next, let’s calculate the total turnaround time. We add up the turnaround times of all processes: 8 + 12 + 22 = 42 units of time. To find the average turnaround time, we divide the total turnaround time by the number of processes, which is 3. Therefore, the average turnaround time is 42 / 3 = 14 units of time.

By calculating the average waiting time and average turnaround time, we can assess the efficiency and performance of the scheduling algorithm used in the system. These metrics provide valuable insights into how long processes have to wait and how quickly they are completed, allowing us to make informed decisions and improvements to optimize the system’s overall performance.

Advantages:

  • Simple and easy to understand and implement.
  • Fairness in terms of the order of process execution.
  • No starvation as each process gets a chance to execute.
  • Provides a predictable execution order, as processes are executed in the order they arrive.
  • Requires minimal overhead, as there is no need for complex algorithms or data structures.
  • Works well for a small number of processes or when the workload is evenly distributed.
  • Can be useful in scenarios where process priority or burst time is not a critical factor.

Disadvantages:

  • High waiting time, especially for long processes that arrive later. This can lead to decreased system performance and user dissatisfaction.
  • No consideration of process priority or burst time, which can result in inefficient resource allocation.
  • Inefficient utilization of CPU if long processes arrive first. This can lead to underutilization of the CPU and increased response time for shorter processes.
  • Not suitable for time-critical or real-time systems, as it does not prioritize processes based on their urgency or deadlines.
  • May lead to a phenomenon known as the “convoy effect,” where a long process holds up the execution of shorter processes behind it.
  • Does not take into account the variability of process execution times, which can result in unpredictable performance.
Scroll to Top