Function Signature
Description
Implements the FIFO (First In First Out) scheduling algorithm, also known as FCFS (First Come First Served). Processes are executed in the order they arrive, forming a queue where the first process to arrive is the first to be executed. Each process runs to completion before the next one starts.Parameters
Array of arrival times for each process. Each element represents when a process arrives in the system.
Array of CPU burst times for each process. Each element represents how long a process needs to execute.
Return Value
Returns an object containing scheduling metrics:Array of start times for each process (indexed by process ID).
Array of completion times for each process (indexed by process ID).
Array of waiting times for each process. Calculated as:
start_time - arrival_time.Array of turnaround times for each process. Calculated as:
completion_time - arrival_time. Represents total time from arrival to completion.Total time required to complete all processes (maximum completion time).
Example Usage
Sample Output
Output Explanation
- Process 0: Arrives at 0, starts at 0, runs for 5 units, completes at 5
- Process 1: Arrives at 1, waits until 5, starts at 5, runs for 3 units, completes at 8
- Process 2: Arrives at 2, waits until 8, starts at 8, runs for 8 units, completes at 16
- Process 3: Arrives at 3, waits until 16, starts at 16, runs for 6 units, completes at 22
Algorithm Details
How It Works
- Processes are sorted by arrival time
- CPU executes processes in order of arrival
- If CPU is idle when a process arrives, it starts immediately
- Otherwise, the process waits for the current process to complete
- Each process runs to completion without interruption
Complexity
- Time Complexity: O(n log n) due to sorting by arrival time
- Space Complexity: O(n) for storing process data and results
Characteristics
- Non-preemptive: Once a process starts, it runs to completion
- Simple: Easy to understand and implement
- Fair: Processes are served in arrival order
- Convoy Effect: Short processes may wait for long processes ahead in queue