For working professionals
For fresh graduates
More
1. Introduction
6. PyTorch
9. AI Tutorial
10. Airflow Tutorial
11. Android Studio
12. Android Tutorial
13. Animation CSS
16. Apex Tutorial
17. App Tutorial
18. Appium Tutorial
21. Armstrong Number
22. ASP Full Form
23. AutoCAD Tutorial
27. Belady's Anomaly
30. Bipartite Graph
35. Button CSS
39. Cobol Tutorial
46. CSS Border
47. CSS Colors
48. CSS Flexbox
49. CSS Float
51. CSS Full Form
52. CSS Gradient
53. CSS Margin
54. CSS nth Child
55. CSS Syntax
56. CSS Tables
57. CSS Tricks
58. CSS Variables
61. Dart Tutorial
63. DCL
65. DES Algorithm
83. Dot Net Tutorial
86. ES6 Tutorial
91. Flutter Basics
92. Flutter Tutorial
95. Golang Tutorial
96. Graphql Tutorial
100. Hive Tutorial
103. Install Bootstrap
107. Install SASS
109. IPv 4 address
110. JCL Programming
111. JQ Tutorial
112. JSON Tutorial
113. JSP Tutorial
114. Junit Tutorial
115. Kadanes Algorithm
116. Kafka Tutorial
117. Knapsack Problem
118. Kth Smallest Element
119. Laravel Tutorial
122. Linear Gradient CSS
129. Memory Hierarchy
133. Mockito tutorial
134. Modem vs Router
135. Mulesoft Tutorial
136. Network Devices
138. Next JS Tutorial
139. Nginx Tutorial
141. Octal to Decimal
142. OLAP Operations
143. Opacity CSS
144. OSI Model
145. CSS Overflow
146. Padding in CSS
148. Perl scripting
149. Phases of Compiler
150. Placeholder CSS
153. Powershell Tutorial
158. Pyspark Tutorial
161. Quality of Service
162. R Language Tutorial
164. RabbitMQ Tutorial
165. Redis Tutorial
166. Redux in React
167. Regex Tutorial
170. Routing Protocols
171. Ruby On Rails
172. Ruby tutorial
173. Scala Tutorial
175. Shadow CSS
178. Snowflake Tutorial
179. Socket Programming
180. Solidity Tutorial
181. SonarQube in Java
182. Spark Tutorial
189. TCP 3 Way Handshake
190. TensorFlow Tutorial
191. Threaded Binary Tree
196. Types of Queue
197. TypeScript Tutorial
198. UDP Protocol
202. Verilog Tutorial
204. Void Pointer
205. Vue JS Tutorial
206. Weak Entity Set
207. What is Bandwidth?
208. What is Big Data
209. Checksum
211. What is Ethernet
214. What is ROM?
216. WPF Tutorial
217. Wireshark Tutorial
218. XML Tutorial
"First come, first serve" (FCFS) is a scheduling algorithm used to manage and prioritize tasks or processes. It is a fundamental method that all students must be aware of in order to learn the core principles of CPU Process Scheduling Algorithms. Stay hooked to the end of this tutorial to know more.
This tutorial is all about the characteristics of FCFS, its advantages, and disadvantages along with several examples that will help you grasp a deeper understanding of this basic concept in computer science.
First Come First Serve (FCFS) is a simple CPU scheduling algorithm used in operating systems. In this approach, processes are executed in the order they arrive in the ready queue. The first process that enters the queue is the first one to be executed by the CPU. FCFS is a non-preemptive scheduling algorithm, meaning that upon execution, processes continue to run until they complete or voluntarily release the CPUs.
Let's understand how FCFS scheduling works with an example:
Suppose we have three processes A, B, and C with their respective burst times:
Assuming they arrive in the order A -> B -> C, the order of execution under FCFS would be:
In this scenario, Process A, being the first to arrive, gets executed first, followed by B and then C.
Now, here's another example with different process burst times:
In this example, we again have three processes X, Y, and Z with their respective burst times:
Assuming they arrive in the order X -> Y -> Z, the order of execution under FCFS would be:
In this example, Process X starts execution first as it arrived first. After Process X completes, Process Y follows, and finally, Process Z runs.
FCFS is a non-preemptive scheduling algorithm, which means that a process will continue to run until it finishes its burst time upon execution. Preemption is not supported in FCFS, so the currently executing process cannot be interrupted by a higher-priority process.
In a preemptive scheduling approach, the operating system can interrupt a running process and allocate the CPU to another process if a higher-priority process becomes available. This means that a running process may be temporarily paused to allow another process with higher priority to execute.
Suppose we have two processes, A and B, with the following burst times and priorities:
In preemptive scheduling, if Process B becomes ready while Process A is running, the operating system might decide to preempt (interrupt) Process A to allow Process B, with a higher priority, to execute. After a while, the operating system could resume executing Process A.
In FCFS, once a process starts execution, it continues until it completes or releases the CPU voluntarily. Other processes waiting in the ready queue have to wait for the currently executing process to finish before they can start execution.
In a non-preemptive scheduling approach, once processes start executing, they run until they complete their burst times or voluntarily release the CPUs. No process can be interrupted by the operating system until it finishes or enters a blocking state.
Let's use the same processes, A and B, with the same burst times and priorities:
In a non-preemptive scheduling scenario, if Process B becomes ready while Process A is running, the operating system will let Process A continue until it completes its execution. Only after Process A finishes or enters a blocking state will Process B get a chance to execute.
The convoy effect is a phenomenon that can occur in FCFS scheduling. It refers to a situation where long processes occupy the CPUs, making the shorter processes wait behind them. This can lead to poor CPU utilization and increased response times for other processes.
For example, consider a scenario where a long I/O-bound process occupies the CPU under FCFS. Other shorter processes that are CPU-bound might queue up behind this process, resulting in longer waiting times for those processes.
The characteristics of FCFS CPU Process Scheduling are as follows:
Here are the benefits of FCFS CPU Process Scheduling:
Here are some of the downsides of FCFS CPU Process Scheduling:
Dijkstra proposed a solution to the problem of wasting wake-up signals by introducing Semaphores in operating systems. Semaphores are variables used to store wake-up calls from producers to consumers, preventing direct signaling and potential wastage. The producer stores wake-up calls in the semaphore variable, which can be read and updated automatically in kernel mode by any consumer when needed.
The implementation of Semaphores in user mode is not feasible due to the possibility of race conditions when multiple processes try to access the variable simultaneously. Thus, Semaphores always require support from the operating system for proper functioning.
There are two categories of Semaphores based on their functionality:
AT: Arrival Time - The time at which a process arrives in the ready queue or becomes ready for execution.
BT: Burst Time - The amount of time a process requires to complete its execution, also known as the CPU time.
CPU: Central Processing Unit - The main processing component of a computer where calculations and data processing take place.
CT: Completion Time - The time at which a process finishes its execution.
FIFO: First In First Out - A queueing principle where the first item to enter the queue is the first one to be removed.
OS: Operating System - Software that manages computer hardware, software resources, and provides services for computer programs.
TAT: Turn Around Time - The total time taken for a process to complete its execution, from arrival to completion.
WT: Waiting Time - The total time a process spends waiting in the ready queue before it starts execution.
Here's an example of implementing the First Come First Serve CPU scheduling algorithm in Java:
Code:
import java.util.*;
class Process {
String name;
int arrivalTime;
int burstTime;
public Process(String name, int arrivalTime, int burstTime) {
this.name = name;
this.arrivalTime = arrivalTime;
this.burstTime = burstTime;
}
}
public class FCFSExample {
public static void main(String[] args) {
List<Process> processes = new ArrayList<>();
processes.add(new Process("Process A", 0, 8));
processes.add(new Process("Process B", 1, 4));
processes.add(new Process("Process C", 2, 6));
int currentTime = 0;
for (Process process : processes) {
if (process.arrivalTime > currentTime) {
currentTime = process.arrivalTime;
}
System.out.println("Executing " + process.name + " from time " + currentTime + " to " + (currentTime + process.burstTime));
currentTime += process.burstTime;
}
}
}
In the above code, we define a Process class with attributes for the process name, arrival time, and burst time. We then create a list of processes and simulate their execution using the FCFS scheduling algorithm. The processes are executed in the order they arrive in the list, and their execution times are printed.
The First Come, First Served (FCFS) scheduling algorithm is beneficial due to its fairness, simplicity, and predictability in managing tasks or processes based on their arrival time. It ensures all tasks are eventually processed, preventing starvation. With low overhead and ease of implementation, FCFS is an efficient choice for scenarios where task priorities and execution times are not critical.
Through this tutorial, we aimed to give you a preliminary understanding of what First Come, First Served is. However, if you want a more nuanced understanding, you should enroll in the specially curated computer science courses by upGrad. With the help of these courses by upGrad you will not only be able to get a better understanding of the concepts but also bag lucrative jobs in leading corporations.
Avoid FCFS in scenarios where some processes are time-sensitive or have higher priority. If your system experiences a mix of long and short-running processes, more advanced scheduling algorithms like Shortest Job First (SJF) or Round Robin might be more suitable.
Yes, FCFS can be part of hybrid scheduling approaches. For example, in multi-level feedback queues, FCFS might be used in one of the priority queues while other algorithms handle different queues with varying priorities and time quantum.
The average waiting time in FCFS depends on the order of process arrival. If shorter processes arrive first, the average waiting time may be lower. However, if longer processes arrive first, the average waiting time can be significantly higher.
Author
Talk to our experts. We are available 7 days a week, 9 AM to 12 AM (midnight)
Indian Nationals
1800 210 2020
Foreign Nationals
+918045604032
1.The above statistics depend on various factors and individual results may vary. Past performance is no guarantee of future results.
2.The student assumes full responsibility for all expenses associated with visas, travel, & related costs. upGrad does not provide any a.