Difference Between FCFS and SJF CPU Scheduling Algorithms
Last Updated :
05 Sep, 2024
CPU scheduling is a key part of how an operating system works. It decides which task (or process) the CPU should work on at any given time. This is important because a CPU can only handle one task at a time, but there are usually many tasks that need to be processed. In this article, we are going to discuss FCFS and SJF CPU scheduling in detail.
First Come First Served CPU Scheduling
FCFS stands for First Come First Served (FCFS). First Come First Served (FCFS) is the simplest type of algorithm. It is a non-preemptive algorithm i.e. the process cannot be interrupted once it starts executing. The FCFS is implemented with the help of a FIFO queue. The processes are put into the ready queue in the order of their arrival time.
The process that arrives first becomes the head of the queue while the others that arrive after are added to the rear of the queue. In the First Come First Served (FCFS) algorithm, the process that arrives first is sent first for execution by the CPU when the CPU is free. The main disadvantage of this algorithm is that the average waiting time is often quite long. It also leads to the convoy effect. This results in lower device or CPU utilization and lower efficiency.
Advantages
- FCFS is essy to understand and easy to implement. The job that arrives first is processed first.
- There's no risk of process starvation.
- Each process is treated equally, based on arrival time, which can be seen as fair from a certain perspective.
Disadvantages
- Processes with longer burst times can cause subsequent processes to wait for a long time.
- A slow process can hold up the entire queue.
- Critical or short processes have to wait for longer processes that arrive earlier.
Shortest Job First CPU Scheduling
SJF stands for Shortest Job First (SJF). Shortest Job First (SJF) Scheduling Algorithm is based upon the burst time of the process. The processes are put into the ready queue based on their burst times. In this algorithm, the process with the least burst time is processed first.
The burst time of only those processes is compared that are present or have arrived until that time. It is also non-preemptive in nature. Its preemptive version is called Shortest Remaining Time First (SRTF) algorithm. The major advantage of this algorithm is that it gives the minimum waiting time for a given set of processes and thus reduces the average waiting time. The disadvantage of this algorithm is that long processes may never be processed by the system and may remain in the queue for very long time leading to starvation of processes.
Note: If two processes have same burst time then the tie is broken using FCFS, i.e., the process that arrived first is processed first.
Advantages
- SJF optimize the average waiting time because shorter processes are prioritized
- By executing shorter jobs first, SJF can improve overall throughput
- Since shorter jobs are executed first, making the CPU more efficient.
Disadvantages
- Predicting the exact burst time for a process can be hard.
- Longer processes may starve.
- If job lengths are not predictable or change frequently, SJF may not be practical.
Difference between FCFS and SJF scheduling algorithm
The difference between First Come First Served (FCFS) and Shortest Job First (SJF) scheduling algorithm are as follows:
First Come First Served (FCFS) | Shortest Job First (SJF) |
---|
First Come First Served (FCFS) executes the processes in the order in which they arrive i.e. the process that arrives first is executed first. | Shortest Job First (SJF) executes the processes based upon their burst time i.e. in ascending order of their burst times. |
FCFS is non preemptive in nature. | SJF is also non-preemptive but its preemptive version is also there called Shortest Remaining Time First (SRTF) algorithm. |
FCFS results in quite long waiting time for the processes and thus increases average waiting time. | The average waiting time for given set of processes is minimum. |
FCFS leads to the convoy effect. | It does not lead to the convoy effect. |
FCFS algorithm is the easiest to implement in any system. | The real difficulty with SJF is knowing the length of the next CPU request or burst. |
A process may have to wait for quite long to get executed depending on the burst time of the processes that have arrived first. | A long process may never get executed and the system may keep executing the short processes. |
FCFS lead to lower device and CPU utilization thereby decreasing the efficiency of the system. | SJF leads to higher effectiveness of the system due to lower average waiting time. |
FCFS results in minimal overhead. | In case of SJF, elapsed time should be recorded, results in more overhead on the processor. |
FCFS does not suffers from starvation | SJF suffers from starvation. |
Conclusion
FCFS is the simplest CPU scheduling algorithm, but it can used to inefficient CPU usage and longer waiting times. SJF is optimization CPU scheduling algorithm, is more complex to implement and can lead to the longer processes. FCFS processes jobs according to their order of arrival. It is poor in performance and easy to implement.
Similar Reads
What is OSI Model? - Layers of OSI Model The OSI (Open Systems Interconnection) Model is a set of rules that explains how different computer systems communicate over a network. OSI Model was developed by the International Organization for Standardization (ISO). The OSI Model consists of 7 layers and each layer has specific functions and re
13 min read
Introduction of ER Model The Entity-Relationship Model (ER Model) is a conceptual model for designing a databases. This model represents the logical structure of a database, including entities, their attributes and relationships between them. Entity: An objects that is stored as data such as Student, Course or Company.Attri
10 min read
DBMS Tutorial â Learn Database Management System Database Management System (DBMS) is a software used to manage data from a database. A database is a structured collection of data that is stored in an electronic device. The data can be text, video, image or any other format.A relational database stores data in the form of tables and a NoSQL databa
7 min read
TCP/IP Model The TCP/IP model (Transmission Control Protocol/Internet Protocol) is a four-layer networking framework that enables reliable communication between devices over interconnected networks. It provides a standardized set of protocols for transmitting data across interconnected networks, ensuring efficie
7 min read
Types of Network Topology Network topology refers to the arrangement of different elements like nodes, links, or devices in a computer network. Common types of network topology include bus, star, ring, mesh, and tree topologies, each with its advantages and disadvantages. In this article, we will discuss different types of n
12 min read
Normal Forms in DBMS In the world of database management, Normal Forms are important for ensuring that data is structured logically, reducing redundancy, and maintaining data integrity. When working with databases, especially relational databases, it is critical to follow normalization techniques that help to eliminate
7 min read
Operating System Tutorial An Operating System(OS) is a software that manages and handles hardware and software resources of a computing device. Responsible for managing and controlling all the activities and sharing of computer resources among different running applications.A low-level Software that includes all the basic fu
4 min read
Computer Network Tutorial A Computer Network is a system where two or more devices are linked together to share data, resources and information. These networks can range from simple setups, like connecting two devices in your home, to massive global systems, like the Internet. Below are the main components of a computer netw
7 min read
ACID Properties in DBMS In the world of DBMS, transactions are fundamental operations that allow us to modify and retrieve data. However, to ensure the integrity of a database, it is important that these transactions are executed in a way that maintains consistency, correctness, and reliability. This is where the ACID prop
8 min read
Types of Operating Systems Operating Systems can be categorized according to different criteria like whether an operating system is for mobile devices (examples Android and iOS) or desktop (examples Windows and Linux). Here, we are going to classify based on functionalities an operating system provides.8 Main Operating System
11 min read