- OS - Home
- OS - Needs
- OS - Overview
- OS - History
- OS - Components
- OS - Structure
- OS - Architecture
- OS - Services
- OS - Properties
- Process Management
- Operating System Processes
- Process Control Block
- Operations on Processes
- Inter Process Communication
- Context Switching
- Multi-threading
- Scheduling Algorithms
- Process Scheduling
- Preemptive and Non-Preemptive Scheduling
- Scheduling Algorithms Overview
- FCFS Scheduling Algorithm
- SJF Scheduling Algorithm
- Round Robin Scheduling Algorithm
- HRRN Scheduling Algorithm
- Priority Scheduling Algorithm
- Multilevel Queue Scheduling
- Lottery Scheduling Algorithm
- Turn Around Time & Waiting Time
- Burst Time in SJF Scheduling
- Process Synchronization
- Process Synchronization
- Critical Section Problem
- Critical Section Synchronization
- Mutual Exclusion Synchronization
- Semaphores
- Counting Semaphores
- Mutex
- Turn Variable
- Bounded Buffer Problem
- Reader Writer Locks
- Test and Set Lock
- Peterson's Solution
- Monitors
- Sleep and Wake
- Race Condition
- OS Deadlock
- Introduction to Deadlock
- Conditions for Deadlock
- Deadlock Handling
- Deadlock Prevention
- Deadlock Avoidance (Banker's Algorithm)
- Deadlock Detection and Recovery
- Deadlock Ignorance
- Memory Management
- Memory Management
- Contiguous Memory Allocation
- Non-Contiguous Memory Allocation
- First Fit Algorithm
- Next Fit Algorithm
- Best Fit Algorithm
- Worst Fit Algorithm
- Fragmentation
- Virtual Memory
- Segmentation
- Buddy System
- Slab Allocation
- Overlays
- Paging and Page Replacement
- Paging
- Demand Paging
- Page Table
- Page Replacement Algorithms
- Optimal Page Replacement Algorithm
- Belady's Anomaly
- Thrashing
- Storage and File Management
- File Systems
- File Attributes
- Structures of Directory
- Linked Index Allocation
- Indexed Allocation
- Disk Scheduling Algorithms
- FCFS Disk Scheduling
- SSTF Disk Scheduling
- SCAN Disk Scheduling
- LOOK Disk Scheduling
- I/O Systems
- I/O Hardware
- I/O Software
- OS Types
- OS - Types
- OS - Batch Processing
- OS - Multiprocessing
- OS - Hybrid
- OS - Monolithic
- OS - Zephyr
- OS - Nix
- OS - Linux
- OS - Blackberry
- OS - Garuda
- OS - Tails
- OS - Clustered
- OS - Haiku
- OS - AIX
- OS - Solus
- OS - Tizen
- OS - Bharat
- OS - Fire
- OS - Bliss
- OS - VxWorks
- OS - Embedded
- OS - Single User
- Miscellaneous Topics
- OS - Security
- OS Questions Answers
- OS - Questions Answers
- OS Useful Resources
- OS - Quick Guide
- OS - Useful Resources
- OS - Discussion
Operating System - FCFS Scheduling Algorithm
In multiprogramming environments, scheduling is performed by the CPU to decide the next process to be executed. This allows multiple CPU processes to exist simultaneously while optimizing utilization of system resources as well as the time of execution. A scheduling strategy defines a procedure to select one process among the processes waiting at the ready queue for execution. There are various scheduling strategies, the elementary strategy among which is the First Come First Serve (FCFS) scheduling algorithm.
FCFS Scheduling
FCFS is considered as simplest CPU-scheduling algorithm. In FCFS algorithm, the process that requests the CPU first is allocated in the CPU first. The implementation of FCFS algorithm is managed with FIFO (First in first out) queue. FCFS scheduling is non-preemptive. Non-preemptive means, once the CPU has been allocated to a process, that process keeps the CPU until it executes a work or job or task and releases the CPU, either by requesting I/O.
Salient Features of FCFS Algorithm
- FCFS is a non-preemptive scheduling algorithm.
- The process that arrives in the ready queue first is allocated to execute in the CPU first.
- Implementation is easy since it does not involve any complex algorithm.
- It does not require any prior knowledge about the processes. Also, if the run time behaviour of the processes changes dynamically, there is no impact on FCFS scheduling algorithm.
- Though this is assures fair scheduling, it may result in long waiting time of individual processes.
Real Life Example Of FCFS Scheduling
As a real life example of FCFS scheduling a billing counter system of shopping mall can be observed. The first person in the line gets the bill done first and then the next person gets the chance to get the bill and make payment and so on. If no priority is given to the VIP customers then the billing system will go on like this (means the first person (first task) in the line will get the bill first and after finishing (executing) the first customers payment the counter boy(CPU) will pay attention to other customers (separate tasks) as they are in the line). As FCFS is non-preemptive type so no priority will be given to the random important tasks.
FCFS Scheduling Mathematical Examples
In CPU-scheduling problems some terms are used while solving the problems, so for conceptual purpose the terms are discussed as follows −
- Arrival time (AT) − Arrival time is the time at which the process arrives in ready queue.
- Burst time (BT) or CPU time of the process − Burst time is the unit of time in which a particular process completes its execution.
- Completion time (CT) − Completion time is the time at which the process has been terminated.
- Turn-around time (TAT) − The total time from arrival time to completion time is known as turn-around time. TAT can be written as,
- Waiting time (WT) Waiting time is the time at which the process waits for its allocation while the previous process is in the CPU for execution. WT is written as,
Turn-around time (TAT) = Completion time (CT) − Arrival time (AT) or TAT = Burst time (BT) + Waiting time (WT)
Waiting time (WT) = Turn-around time (TAT) − Burst time (BT)
- Response time (RT) − Response time is the time at which CPU has been allocated to a particular process first time.
- In case of non-preemptive scheduling, generally Waiting time and Response time is same.
- Gantt chart − Gantt chart is a visualization which helps to scheduling and managing particular tasks in a project. It is used while solving scheduling problems, for a concept of how the processes are being allocated in different algorithms.
Problem 1
Consider the given table below and find Completion time (CT), Turn-around time (TAT), Waiting time (WT), Response time (RT), Average Turn-around time and Average Waiting time.
| Process ID | Arrival time | Burst time |
|---|---|---|
| P1 | 2 | 2 |
| P2 | 5 | 6 |
| P3 | 0 | 4 |
| P4 | 0 | 7 |
| P5 | 7 | 4 |
Solution
Gantt chart
For this problem CT, TAT, WT, RT is shown in the given table
| Process ID | Arrival time | Burst time | CT | TAT=CT-AT | WT=TAT-BT | RT |
|---|---|---|---|---|---|---|
| P1 | 2 | 2 | 13 | 13-2= 11 | 11-2= 9 | 9 |
| P2 | 5 | 6 | 19 | 19-5= 14 | 14-6= 8 | 8 |
| P3 | 0 | 4 | 4 | 4-0= 4 | 4-4= 0 | 0 |
| P4 | 0 | 7 | 11 | 11-0= 11 | 11-7= 4 | 4 |
| P5 | 7 | 4 | 23 | 23-7= 16 | 16-4= 12 | 12 |
Average Waiting time = (9+8+0+4+12)/5 = 33/5 = 6.6 time unit (time unit can be considered as milliseconds)
Average Turn-around time = (11+14+4+11+16)/5 = 56/5 = 11.2 time unit (time unit can be considered as milliseconds)
Problem 2
Consider the given table below and find Completion time (CT), Turn-around time (TAT), Waiting time (WT), Response time (RT), Average Turn-around time and Average Waiting time.
| Process ID | Arrival time | Burst time |
|---|---|---|
| P1 | 2 | 2 |
| P2 | 0 | 1 |
| P3 | 2 | 3 |
| P4 | 3 | 5 |
| P5 | 4 | 5 |
Solution
Gantt chart
For this problem CT, TAT, WT, RT is shown in the given table
| Process ID | Arrival time | Burst time | CT | TAT=CT-AT | WT=TAT-BT | RT |
|---|---|---|---|---|---|---|
| P1 | 2 | 2 | 4 | 4-2= 2 | 2-2= 0 | 0 |
| P2 | 0 | 1 | 1 | 1-0= 1 | 1-1= 0 | 0 |
| P3 | 2 | 3 | 7 | 7-2= 5 | 5-3= 2 | 2 |
| P4 | 3 | 5 | 12 | 12-3= 9 | 9-5= 4 | 4 |
| P5 | 4 | 5 | 17 | 17-4= 13 | 13-5= 8 | 8 |
Average Waiting time = (0+0+2+4+8)/5 = 14/5 = 2.8 time unit (time unit can be considered as milliseconds)
Average Turn-around time = (2+1+5+9+13)/5 = 30/5 = 6 time unit (time unit can be considered as milliseconds)
*In idle (not-active) CPU period, no process is scheduled to be terminated so in this time it remains void for a little time.
Advantages Of FCFS Scheduling
- It is an easy algorithm to implement since it does not include any complex way.
- Every task should be executed simultaneously as it follows FIFO queue.
- FCFS does not give priority to any random important tasks first so its a fair scheduling.
Disadvantages Of FCFS Scheduling
- FCFS results in convoy effect which means if a process with higher burst time comes first in the ready queue then the processes with lower burst time may get blocked and that processes with lower burst time may not be able to get the CPU if the higher burst time task takes time forever.
- If a process with long burst time comes in the line first then the other short burst time process have to wait for a long time, so it is not much good as time-sharing systems.
- Since it is non-preemptive, it does not release the CPU before it completes its task execution completely.
*Convoy effect and starvation sounds similar but there is slight difference, so it is advised to not treat these both terms as same words.
Conclusion
Although FCFS is simple to implement and understand, FCFS is not good for interactive system and not used in modern operating systems. The Convoy effect in the FCFS can be prevented using other CPU-scheduling preemptive algorithms such as Round-robin scheduling.